Skip to main content

Client

Struct Client 

Source
pub struct Client {
    pub auth: AuthClient,
    pub communication: CommunicationClient,
    /* private fields */
}
Expand description

🚀 OpenLark客户端 - 极简设计

§特性

  • 零配置启动:Client::from_env()
  • 单入口:meta 链式字段访问(client.docs/...
  • 编译时feature优化
  • 高性能异步
  • 现代化错误处理

§示例

use openlark_client::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    // 从环境变量创建客户端
    let client = Client::from_env()?;

    // meta 链式入口(需要对应 feature)
    // - 通讯:client.communication.im...
    // - 文档:client.docs.ccm...
    // - 认证:client.auth.app / client.auth.user / client.auth.oauth

    Ok(())
}

Fields§

§auth: AuthClient

Auth meta 调用链入口:client.auth.app / client.auth.user / client.auth.oauth

§communication: CommunicationClient

Communication meta 调用链入口:client.communication.im / client.communication.contact …

Implementations§

Source§

impl Client

Source

pub fn from_env() -> Result<Self>

🔥 从环境变量创建客户端

§环境变量
export OPENLARK_APP_ID=your_app_id
export OPENLARK_APP_SECRET=your_app_secret
export OPENLARK_BASE_URL=https://open.feishu.cn  # 可选
§返回值

返回配置好的客户端实例或错误

§示例
use openlark_client::Client;

let _client = Client::from_env();
Source

pub fn builder() -> ClientBuilder

🏗️ 创建构建器

Source

pub fn config(&self) -> &Config

🔧 获取客户端配置

Source

pub fn registry(&self) -> &DefaultServiceRegistry

📋 获取服务注册表

Source

pub fn core_config(&self) -> &Config

🔧 获取底层 core 配置(高级用法/调试用)

Source

pub fn api_config(&self) -> &Config

🔧 获取可直接传给函数式 API 的认证后配置

Self::core_config 返回同一份配置,保留这个别名是为了让 业务侧更容易理解它的用途:可直接传给 openlark_docs::*openlark_auth::* 等函数式 API。

Source

pub fn is_configured(&self) -> bool

✅ 检查客户端是否已正确配置

Source

pub fn with_config(config: Config) -> Result<Self>

🆕 创建带有自定义配置的客户端

Source

pub async fn execute_with_context<F, T>( &self, operation: &str, f: F, ) -> Result<T>
where F: Future<Output = Result<T>>,

🔧 执行带有错误上下文的操作

Trait Implementations§

Source§

impl ClientErrorHandling for Client

Source§

fn handle_error<T>(&self, result: Result<T>, operation: &str) -> Result<T>

处理错误并添加客户端上下文
Source§

async fn handle_async_error<T, F>(&self, f: F, operation: &str) -> Result<T>
where F: Future<Output = Result<T>>,

处理异步错误并添加客户端上下文
Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl LarkClient for Client

Source§

fn config(&self) -> &Config

🔧 获取客户端配置
Source§

fn is_configured(&self) -> bool

✅ 检查客户端是否已正确配置 Read more
Source§

fn app_id(&self) -> &str

🔍 获取应用ID
Source§

fn app_secret(&self) -> &str

🔑 获取应用密钥
Source§

fn base_url(&self) -> &str

🌐 获取API基础URL
Source§

fn timeout(&self) -> Duration

⏱️ 获取请求超时时间
Source§

fn retry_count(&self) -> u32

🔄 获取重试次数
Source§

fn is_log_enabled(&self) -> bool

📝 检查是否启用了日志

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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: 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: 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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