Skip to main content

WecomClient

Struct WecomClient 

Source
pub struct WecomClient { /* private fields */ }
Expand description

WeCom 客户端:认证、服务发现与方法调用的统一入口。

WecomClientBuilder 构建后即可直接使用:

let client = WecomClientBuilder::new()
    .token_provider(Arc::new(provider))
    .build()
    .await?;

// 程序化调用(服务/方法名由 discovery 下发)
let svc = client.service("hr").await?;
let result = svc.method(&["users", "list"])?.invoke(json!({})).await?;

Implementations§

Source§

impl WecomClient

Source

pub fn from_transport(transport: Transport) -> Result<Self, Error>

用已构建的 transport 组装客户端(自动挂网关协议端点目录)。

适合需要完全自定义 transport 的调用方;常规路径请用 WecomClientBuilder

§Errors

wecomx::Client 构建失败时返回 wecomx::Error

Source

pub fn from_client(inner: Client) -> Self

包裹一个已配置好的 wecomx::Client(不改动其任何配置)。

Source

pub fn inner(&self) -> &Client

底层 wecomx::Client(需要沙箱 FS、helper、扩展命令等高级配置时使用)。

Source

pub fn into_inner(self) -> Client

消耗自身,返回底层 wecomx::Client

Source

pub fn transport(&self) -> &Transport

带鉴权的 transport(可注入默认 header、extension 等)。

Source

pub async fn list_services(&self) -> Result<Vec<ServiceInfo>, Error>

列出 discovery 下发的服务目录。

§Errors

服务发现失败时返回 wecomx::Error

Source

pub async fn service(&self, name: &str) -> Result<ServiceHandle<'_>, Error>

获取指定服务的句柄(服务名由 discovery 下发)。

§Errors

服务不存在或发现失败时返回 wecomx::Error

Source

pub async fn method(&self, path: &[&str]) -> Result<MethodHandle<'_>, Error>

按路径(服务名 + 资源段 + 方法名)直接获取方法句柄。

§Errors

方法不存在或发现失败时返回 wecomx::Error

Source

pub fn run(&self, argv: Vec<String>) -> CliRun<'_>

CLI 风格的 argv 调度入口(与 wecom-cli 同一套命令模型)。

返回 wecomx::CliRunIntoFuture),.await 即执行:

client.run(vec!["wecom".into(), "hr".into(), "users".into(), "list".into()])
    .await?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more