wasmcloud-advent-of-code-interface 0.1.0

Interface library for Advent of Code solutions written for wasmCloud
Documentation
// This file is @generated by wasmcloud/weld-codegen 0.6.0.
// It is not intended for manual editing.
// namespace: org.example.interfaces.aocsolution

#[allow(unused_imports)]
use async_trait::async_trait;
#[allow(unused_imports)]
use serde::{Deserialize, Serialize};
#[allow(unused_imports)]
use std::{borrow::Borrow, borrow::Cow, io::Write, string::ToString};
#[allow(unused_imports)]
use wasmbus_rpc::{
    cbor::*,
    common::{
        deserialize, message_format, serialize, Context, Message, MessageDispatch, MessageFormat,
        SendOpts, Transport,
    },
    error::{RpcError, RpcResult},
    Timestamp,
};

#[allow(dead_code)]
pub const SMITHY_VERSION: &str = "1.0";

/// Description of Aocsolution service
/// wasmbus.actorReceive
#[async_trait]
pub trait Aocsolution {
    /// Used to retrive the solution for part one of an AdventOfCode solution
    async fn part_one(&self, ctx: &Context) -> RpcResult<String>;
    /// Used to retrive the solution for part two of an AdventOfCode solution
    async fn part_two(&self, ctx: &Context) -> RpcResult<String>;
}

/// AocsolutionReceiver receives messages defined in the Aocsolution service trait
/// Description of Aocsolution service
#[doc(hidden)]
#[async_trait]
pub trait AocsolutionReceiver: MessageDispatch + Aocsolution {
    async fn dispatch(&self, ctx: &Context, message: Message<'_>) -> Result<Vec<u8>, RpcError> {
        match message.method {
            "PartOne" => {
                let resp = Aocsolution::part_one(self, ctx).await?;
                let buf = wasmbus_rpc::common::serialize(&resp)?;

                Ok(buf)
            }
            "PartTwo" => {
                let resp = Aocsolution::part_two(self, ctx).await?;
                let buf = wasmbus_rpc::common::serialize(&resp)?;

                Ok(buf)
            }
            _ => Err(RpcError::MethodNotHandled(format!(
                "Aocsolution::{}",
                message.method
            ))),
        }
    }
}

/// AocsolutionSender sends messages to a Aocsolution service
/// Description of Aocsolution service
/// client for sending Aocsolution messages
#[derive(Debug)]
pub struct AocsolutionSender<T: Transport> {
    transport: T,
}

impl<T: Transport> AocsolutionSender<T> {
    /// Constructs a AocsolutionSender with the specified transport
    pub fn via(transport: T) -> Self {
        Self { transport }
    }

    pub fn set_timeout(&self, interval: std::time::Duration) {
        self.transport.set_timeout(interval);
    }
}

#[cfg(not(target_arch = "wasm32"))]
impl<'send> AocsolutionSender<wasmbus_rpc::provider::ProviderTransport<'send>> {
    /// Constructs a Sender using an actor's LinkDefinition,
    /// Uses the provider's HostBridge for rpc
    pub fn for_actor(ld: &'send wasmbus_rpc::core::LinkDefinition) -> Self {
        Self {
            transport: wasmbus_rpc::provider::ProviderTransport::new(ld, None),
        }
    }
}
#[cfg(target_arch = "wasm32")]
impl AocsolutionSender<wasmbus_rpc::actor::prelude::WasmHost> {
    /// Constructs a client for actor-to-actor messaging
    /// using the recipient actor's public key
    pub fn to_actor(actor_id: &str) -> Self {
        let transport =
            wasmbus_rpc::actor::prelude::WasmHost::to_actor(actor_id.to_string()).unwrap();
        Self { transport }
    }
}
#[async_trait]
impl<T: Transport + std::marker::Sync + std::marker::Send> Aocsolution for AocsolutionSender<T> {
    #[allow(unused)]
    /// Used to retrive the solution for part one of an AdventOfCode solution
    async fn part_one(&self, ctx: &Context) -> RpcResult<String> {
        let buf = *b"";
        let resp = self
            .transport
            .send(
                ctx,
                Message {
                    method: "Aocsolution.PartOne",
                    arg: Cow::Borrowed(&buf),
                },
                None,
            )
            .await?;

        let value: String = wasmbus_rpc::common::deserialize(&resp)
            .map_err(|e| RpcError::Deser(format!("'{}': String", e)))?;
        Ok(value)
    }
    #[allow(unused)]
    /// Used to retrive the solution for part two of an AdventOfCode solution
    async fn part_two(&self, ctx: &Context) -> RpcResult<String> {
        let buf = *b"";
        let resp = self
            .transport
            .send(
                ctx,
                Message {
                    method: "Aocsolution.PartTwo",
                    arg: Cow::Borrowed(&buf),
                },
                None,
            )
            .await?;

        let value: String = wasmbus_rpc::common::deserialize(&resp)
            .map_err(|e| RpcError::Deser(format!("'{}': String", e)))?;
        Ok(value)
    }
}