Client

Struct Client 

Source
pub struct Client {
    pub url: String,
    pub model: Model,
    pub region: Option<String>,
    pub project_id: Option<String>,
    pub response_type: ResponseType,
}
Expand description

Manages the specific API connection

Fields§

§url: String§model: Model§region: Option<String>§project_id: Option<String>§response_type: ResponseType

Implementations§

Source§

impl Client

Implements the functions for the API client. TODO: This is getting unwieldy. We need to refactor this into a more manageable state. See Issue #26 - ‘Code tidy and improvement’

Source

pub fn new(api_key: String) -> Self

Creates a default new public API client.

Examples found in repository?
examples/text_request.rs (line 19)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16    env_logger::init();
17
18    // Either run as a standard text request or a stream generate content request
19    let client = Client::new(env::var("API_KEY").unwrap().to_string());
20
21    let txt_request = Request {
22        contents: vec![Content {
23            role: Role::User,
24            parts: vec![Part {
25                text: Some("Give me a recipe for banana bread.".to_string()),
26                inline_data: None,
27                file_data: None,
28                video_metadata: None,
29            }],
30        }],
31        tools: vec![],
32        safety_settings: vec![],
33        generation_config: None,
34
35        #[cfg(feature = "beta")]
36        system_instruction: None,
37    };
38
39    let response = client.post(30, &txt_request).await?;
40
41    info!("{:#?}", response);
42
43    Ok(())
44}
Source

pub fn new_from_response_type( response_type: ResponseType, api_key: String, ) -> Self

Creates a default new public API client for a specified response type.

Examples found in repository?
examples/get_model.rs (lines 15-18)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    env_logger::init();
14
15    let client = Client::new_from_response_type(
16        ResponseType::GetModel,
17        env::var("API_KEY").unwrap().to_string(),
18    );
19
20    let response = client.get_model(30).await?;
21
22    info!("{:#?}", response);
23
24    Ok(())
25}
More examples
Hide additional examples
examples/get_models.rs (lines 15-18)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    env_logger::init();
14
15    let client = Client::new_from_response_type(
16        ResponseType::GetModelList,
17        env::var("API_KEY").unwrap().to_string(),
18    );
19
20    let response = client.get_model_list(30).await?;
21
22    info!("{:#?}", response);
23
24    Ok(())
25}
examples/count_tokens.rs (lines 20-23)
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18    env_logger::init();
19
20    let client = Client::new_from_response_type(
21        ResponseType::CountTokens,
22        env::var("API_KEY").unwrap().to_string(),
23    );
24
25    let txt_request = Request {
26        contents: vec![Content {
27            role: Role::User,
28            parts: vec![Part {
29                text: Some("Write a story about a magic backpack.".to_string()),
30                inline_data: None,
31                file_data: None,
32                video_metadata: None,
33            }],
34        }],
35        tools: vec![],
36        safety_settings: vec![],
37        generation_config: None,
38
39        #[cfg(feature = "beta")]
40        system_instruction: None,
41    };
42
43    let response = client.post(30, &txt_request).await?;
44
45    info!("{:#?}", response);
46
47    Ok(())
48}
Source

pub fn new_from_model(model: Model, api_key: String) -> Self

Create a new public API client for a specified model.

Examples found in repository?
examples/text_request_json.rs (lines 35-38)
22async fn main() -> Result<(), Box<dyn std::error::Error>> {
23    env_logger::init();
24
25    #[cfg(not(feature = "beta"))]
26    {
27        log::error!("JSON-mode only works currently on Gemini 1.5 Pro and on 'beta'");
28
29        Ok(())
30    }
31
32    #[cfg(feature = "beta")]
33    {
34        // Either run as a standard text request or a stream generate content request
35        let client = Client::new_from_model(
36            Model::Gemini1_5Pro,
37            env::var("API_KEY").unwrap().to_string(),
38        );
39
40        let prompt = r#"List 5 popular cookie recipes using this JSON schema: 
41                        { "type": "object", "properties": { "recipe_name": { "type": "string" }}}"#
42            .to_string();
43
44        log::info!("Prompt: {:#?}", prompt);
45
46        let txt_request = Request {
47            contents: vec![Content {
48                role: Role::User,
49                parts: vec![Part {
50                    text: Some(prompt),
51                    inline_data: None,
52                    file_data: None,
53                    video_metadata: None,
54                }],
55            }],
56            tools: vec![],
57            safety_settings: vec![],
58            generation_config: Some(GenerationConfig {
59                temperature: None,
60                top_p: None,
61                top_k: None,
62                candidate_count: None,
63                max_output_tokens: None,
64                stop_sequences: None,
65                response_mime_type: Some("application/json".to_string()),
66                response_schema: None,
67            }),
68
69            system_instruction: None,
70        };
71
72        let response = client.post(30, &txt_request).await?;
73
74        log::info!("{:#?}", response);
75
76        Ok(())
77    }
78}
Source

pub fn new_from_model_response_type( model: Model, api_key: String, response_type: ResponseType, ) -> Self

Create a new public API client for a specified model.

Examples found in repository?
examples/text_request_stream.rs (lines 27-31)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16    env_logger::init();
17
18    let token = match env::var("API_KEY") {
19        Ok(v) => v,
20        Err(e) => {
21            let msg = "$API_KEY not found".to_string();
22            panic!("{e:?}:{msg}");
23        }
24    };
25
26    // Either run as a standard text request or a stream generate content request
27    let client = Client::new_from_model_response_type(
28        google_generative_ai_rs::v1::gemini::Model::Gemini1_0Pro,
29        token.clone(),
30        ResponseType::StreamGenerateContent,
31    );
32
33    println!("token {:#?}", token);
34
35    let txt_request = Request {
36        contents: vec![Content {
37            role: Role::User,
38            parts: vec![Part {
39                text: Some("Give me a recipe for banana bread.".to_string()),
40                inline_data: None,
41                file_data: None,
42                video_metadata: None,
43            }],
44        }],
45        tools: vec![],
46        safety_settings: vec![],
47        generation_config: None,
48
49        #[cfg(feature = "beta")]
50        system_instruction: None,
51    };
52
53    let response = client.post(30, &txt_request).await?;
54
55    println!("output streaming content");
56
57    if let Some(stream_response) = response.streamed() {
58        if let Some(json_stream) = stream_response.response_stream {
59            Client::for_each_async(json_stream, move |response: GeminiResponse| async move {
60                let mut lock = stdout().lock();
61                write!(
62                    lock,
63                    "{}",
64                    response.candidates[0].content.parts[0]
65                        .text
66                        .clone()
67                        .unwrap()
68                        .as_str()
69                )
70                .unwrap();
71            })
72            .await
73        }
74    }
75
76    Ok(())
77}
Source

pub async fn post( &self, timeout: u64, api_request: &Request, ) -> Result<PostResult, GoogleAPIError>

Examples found in repository?
examples/count_tokens.rs (line 43)
17async fn main() -> Result<(), Box<dyn std::error::Error>> {
18    env_logger::init();
19
20    let client = Client::new_from_response_type(
21        ResponseType::CountTokens,
22        env::var("API_KEY").unwrap().to_string(),
23    );
24
25    let txt_request = Request {
26        contents: vec![Content {
27            role: Role::User,
28            parts: vec![Part {
29                text: Some("Write a story about a magic backpack.".to_string()),
30                inline_data: None,
31                file_data: None,
32                video_metadata: None,
33            }],
34        }],
35        tools: vec![],
36        safety_settings: vec![],
37        generation_config: None,
38
39        #[cfg(feature = "beta")]
40        system_instruction: None,
41    };
42
43    let response = client.post(30, &txt_request).await?;
44
45    info!("{:#?}", response);
46
47    Ok(())
48}
More examples
Hide additional examples
examples/text_request.rs (line 39)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16    env_logger::init();
17
18    // Either run as a standard text request or a stream generate content request
19    let client = Client::new(env::var("API_KEY").unwrap().to_string());
20
21    let txt_request = Request {
22        contents: vec![Content {
23            role: Role::User,
24            parts: vec![Part {
25                text: Some("Give me a recipe for banana bread.".to_string()),
26                inline_data: None,
27                file_data: None,
28                video_metadata: None,
29            }],
30        }],
31        tools: vec![],
32        safety_settings: vec![],
33        generation_config: None,
34
35        #[cfg(feature = "beta")]
36        system_instruction: None,
37    };
38
39    let response = client.post(30, &txt_request).await?;
40
41    info!("{:#?}", response);
42
43    Ok(())
44}
examples/vertex_count_tokens.rs (line 53)
24async fn main() -> Result<(), Box<dyn std::error::Error>> {
25    env_logger::init();
26    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
27    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
28
29    let client = Client::new_from_region_project_id_response_type(
30        region.to_string(),
31        project_id.to_string(),
32        ResponseType::CountTokens,
33    );
34
35    let txt_request = Request {
36        contents: vec![Content {
37            role: Role::User,
38            parts: vec![Part {
39                text: Some("Write a story about a magic backpack.".to_string()),
40                inline_data: None,
41                file_data: None,
42                video_metadata: None,
43            }],
44        }],
45        tools: vec![],
46        safety_settings: vec![],
47        generation_config: None,
48
49        #[cfg(feature = "beta")]
50        system_instruction: None,
51    };
52
53    let response = client.post(30, &txt_request).await?;
54
55    info!("{:#?}", response);
56
57    Ok(())
58}
examples/vertex_text_request.rs (line 53)
24async fn main() -> Result<(), Box<dyn std::error::Error>> {
25    env_logger::init();
26    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
27    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
28
29    let client = Client::new_from_region_project_id_response_type(
30        region.to_string(),
31        project_id.to_string(),
32        ResponseType::GenerateContent,
33    );
34
35    let txt_request = Request {
36        contents: vec![Content {
37            role: Role::User,
38            parts: vec![Part {
39                text: Some("Give me a recipe for banana bread.".to_string()),
40                inline_data: None,
41                file_data: None,
42                video_metadata: None,
43            }],
44        }],
45        tools: vec![],
46        safety_settings: vec![],
47        generation_config: None,
48
49        #[cfg(feature = "beta")]
50        system_instruction: None,
51    };
52
53    let response = client.post(30, &txt_request).await?;
54
55    info!("{:#?}", response);
56
57    Ok(())
58}
examples/vertex_text_request_stream.rs (line 48)
23async fn main() -> Result<(), Box<dyn std::error::Error>> {
24    env_logger::init();
25    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
26    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
27
28    let client = Client::new_from_region_project_id(region.to_string(), project_id.to_string());
29
30    let txt_request = Request {
31        contents: vec![Content {
32            role: Role::User,
33            parts: vec![Part {
34                text: Some("Give me a recipe for banana bread.".to_string()),
35                inline_data: None,
36                file_data: None,
37                video_metadata: None,
38            }],
39        }],
40        tools: vec![],
41        safety_settings: vec![],
42        generation_config: None,
43
44        #[cfg(feature = "beta")]
45        system_instruction: None,
46    };
47
48    let response = client.post(30, &txt_request).await?;
49
50    println!("output streaming content");
51
52    if let Some(stream_response) = response.streamed() {
53        if let Some(json_stream) = stream_response.response_stream {
54            Client::for_each_async(json_stream, move |response: GeminiResponse| async move {
55                let mut lock = stdout().lock();
56                write!(
57                    lock,
58                    "{}",
59                    response.candidates[0].content.parts[0]
60                        .text
61                        .clone()
62                        .unwrap()
63                        .as_str()
64                )
65                .unwrap();
66            })
67            .await
68        }
69    }
70
71    Ok(())
72}
examples/text_request_json.rs (line 72)
22async fn main() -> Result<(), Box<dyn std::error::Error>> {
23    env_logger::init();
24
25    #[cfg(not(feature = "beta"))]
26    {
27        log::error!("JSON-mode only works currently on Gemini 1.5 Pro and on 'beta'");
28
29        Ok(())
30    }
31
32    #[cfg(feature = "beta")]
33    {
34        // Either run as a standard text request or a stream generate content request
35        let client = Client::new_from_model(
36            Model::Gemini1_5Pro,
37            env::var("API_KEY").unwrap().to_string(),
38        );
39
40        let prompt = r#"List 5 popular cookie recipes using this JSON schema: 
41                        { "type": "object", "properties": { "recipe_name": { "type": "string" }}}"#
42            .to_string();
43
44        log::info!("Prompt: {:#?}", prompt);
45
46        let txt_request = Request {
47            contents: vec![Content {
48                role: Role::User,
49                parts: vec![Part {
50                    text: Some(prompt),
51                    inline_data: None,
52                    file_data: None,
53                    video_metadata: None,
54                }],
55            }],
56            tools: vec![],
57            safety_settings: vec![],
58            generation_config: Some(GenerationConfig {
59                temperature: None,
60                top_p: None,
61                top_k: None,
62                candidate_count: None,
63                max_output_tokens: None,
64                stop_sequences: None,
65                response_mime_type: Some("application/json".to_string()),
66                response_schema: None,
67            }),
68
69            system_instruction: None,
70        };
71
72        let response = client.post(30, &txt_request).await?;
73
74        log::info!("{:#?}", response);
75
76        Ok(())
77    }
78}
Source

pub async fn for_each_async<F, Fut>( stream: Pin<Box<dyn Stream<Item = Result<Value, StreamBodyError>> + Send>>, consumer: F, )
where F: FnMut(GeminiResponse) -> Fut + Send + 'static, Fut: Future<Output = ()>,

Applies an asynchronous operation to each item in a stream, potentially concurrently.

This function retrieves each item from the provided stream, processes it using the given consumer callback, and awaits the futures produced by the consumer. The concurrency level is unbounded, meaning items will be processed as soon as they are ready without a limit.

§Type Parameters
  • F: The type of the consumer closure. It must accept a GeminiResponse and return a future.
  • Fut: The future type returned by the consumer closure. It must resolve to ().
§Parameters
  • stream: A Pin<Box<dyn Stream>> that produces items of type Result<serde_json::Value, StreamBodyError>. The stream already needs to be pinned and boxed when passed into this function.
  • consumer: A mutable closure that is called for each GeminiResponse. The results of the closure are futures which will be awaited to completion. This closure needs to be Send and 'static to allow for concurrent and potentially multi-threaded execution.
Examples found in repository?
examples/vertex_text_request_stream.rs (lines 54-66)
23async fn main() -> Result<(), Box<dyn std::error::Error>> {
24    env_logger::init();
25    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
26    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
27
28    let client = Client::new_from_region_project_id(region.to_string(), project_id.to_string());
29
30    let txt_request = Request {
31        contents: vec![Content {
32            role: Role::User,
33            parts: vec![Part {
34                text: Some("Give me a recipe for banana bread.".to_string()),
35                inline_data: None,
36                file_data: None,
37                video_metadata: None,
38            }],
39        }],
40        tools: vec![],
41        safety_settings: vec![],
42        generation_config: None,
43
44        #[cfg(feature = "beta")]
45        system_instruction: None,
46    };
47
48    let response = client.post(30, &txt_request).await?;
49
50    println!("output streaming content");
51
52    if let Some(stream_response) = response.streamed() {
53        if let Some(json_stream) = stream_response.response_stream {
54            Client::for_each_async(json_stream, move |response: GeminiResponse| async move {
55                let mut lock = stdout().lock();
56                write!(
57                    lock,
58                    "{}",
59                    response.candidates[0].content.parts[0]
60                        .text
61                        .clone()
62                        .unwrap()
63                        .as_str()
64                )
65                .unwrap();
66            })
67            .await
68        }
69    }
70
71    Ok(())
72}
More examples
Hide additional examples
examples/text_request_stream.rs (lines 59-71)
15async fn main() -> Result<(), Box<dyn std::error::Error>> {
16    env_logger::init();
17
18    let token = match env::var("API_KEY") {
19        Ok(v) => v,
20        Err(e) => {
21            let msg = "$API_KEY not found".to_string();
22            panic!("{e:?}:{msg}");
23        }
24    };
25
26    // Either run as a standard text request or a stream generate content request
27    let client = Client::new_from_model_response_type(
28        google_generative_ai_rs::v1::gemini::Model::Gemini1_0Pro,
29        token.clone(),
30        ResponseType::StreamGenerateContent,
31    );
32
33    println!("token {:#?}", token);
34
35    let txt_request = Request {
36        contents: vec![Content {
37            role: Role::User,
38            parts: vec![Part {
39                text: Some("Give me a recipe for banana bread.".to_string()),
40                inline_data: None,
41                file_data: None,
42                video_metadata: None,
43            }],
44        }],
45        tools: vec![],
46        safety_settings: vec![],
47        generation_config: None,
48
49        #[cfg(feature = "beta")]
50        system_instruction: None,
51    };
52
53    let response = client.post(30, &txt_request).await?;
54
55    println!("output streaming content");
56
57    if let Some(stream_response) = response.streamed() {
58        if let Some(json_stream) = stream_response.response_stream {
59            Client::for_each_async(json_stream, move |response: GeminiResponse| async move {
60                let mut lock = stdout().lock();
61                write!(
62                    lock,
63                    "{}",
64                    response.candidates[0].content.parts[0]
65                        .text
66                        .clone()
67                        .unwrap()
68                        .as_str()
69                )
70                .unwrap();
71            })
72            .await
73        }
74    }
75
76    Ok(())
77}
Source

pub async fn get_token_count( &self, client: Client, api_request: &Request, ) -> Result<TokenCount, GoogleAPIError>

Parameters:

  • timeout - the timeout in seconds
  • api_request - the request to send to check token count
Source

pub async fn get_model( &self, timeout: u64, ) -> Result<ModelInformation, GoogleAPIError>

Gets a model - see: “https://ai.google.dev/tutorials/rest_quickstart#get_model” Parameters:

  • timeout - the timeout in seconds
Examples found in repository?
examples/get_model.rs (line 20)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    env_logger::init();
14
15    let client = Client::new_from_response_type(
16        ResponseType::GetModel,
17        env::var("API_KEY").unwrap().to_string(),
18    );
19
20    let response = client.get_model(30).await?;
21
22    info!("{:#?}", response);
23
24    Ok(())
25}
Source

pub async fn get_model_list( &self, timeout: u64, ) -> Result<ModelInformationList, GoogleAPIError>

Gets a list of models - see: “https://ai.google.dev/tutorials/rest_quickstart#list_models” Parameters:

  • timeout - the timeout in seconds
Examples found in repository?
examples/get_models.rs (line 20)
12async fn main() -> Result<(), Box<dyn std::error::Error>> {
13    env_logger::init();
14
15    let client = Client::new_from_response_type(
16        ResponseType::GetModelList,
17        env::var("API_KEY").unwrap().to_string(),
18    );
19
20    let response = client.get_model_list(30).await?;
21
22    info!("{:#?}", response);
23
24    Ok(())
25}
Source§

impl Client

Source

pub fn new_from_region_project_id(region: String, project_id: String) -> Self

Create a new private API client (Vertex AI) using the default model, Gemini-pro.

Parameters:

  • region - the GCP region to use
  • project_id - the GCP account project_id to use
Examples found in repository?
examples/vertex_text_request_stream.rs (line 28)
23async fn main() -> Result<(), Box<dyn std::error::Error>> {
24    env_logger::init();
25    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
26    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
27
28    let client = Client::new_from_region_project_id(region.to_string(), project_id.to_string());
29
30    let txt_request = Request {
31        contents: vec![Content {
32            role: Role::User,
33            parts: vec![Part {
34                text: Some("Give me a recipe for banana bread.".to_string()),
35                inline_data: None,
36                file_data: None,
37                video_metadata: None,
38            }],
39        }],
40        tools: vec![],
41        safety_settings: vec![],
42        generation_config: None,
43
44        #[cfg(feature = "beta")]
45        system_instruction: None,
46    };
47
48    let response = client.post(30, &txt_request).await?;
49
50    println!("output streaming content");
51
52    if let Some(stream_response) = response.streamed() {
53        if let Some(json_stream) = stream_response.response_stream {
54            Client::for_each_async(json_stream, move |response: GeminiResponse| async move {
55                let mut lock = stdout().lock();
56                write!(
57                    lock,
58                    "{}",
59                    response.candidates[0].content.parts[0]
60                        .text
61                        .clone()
62                        .unwrap()
63                        .as_str()
64                )
65                .unwrap();
66            })
67            .await
68        }
69    }
70
71    Ok(())
72}
Source

pub fn new_from_region_project_id_response_type( region: String, project_id: String, response_type: ResponseType, ) -> Self

Examples found in repository?
examples/vertex_count_tokens.rs (lines 29-33)
24async fn main() -> Result<(), Box<dyn std::error::Error>> {
25    env_logger::init();
26    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
27    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
28
29    let client = Client::new_from_region_project_id_response_type(
30        region.to_string(),
31        project_id.to_string(),
32        ResponseType::CountTokens,
33    );
34
35    let txt_request = Request {
36        contents: vec![Content {
37            role: Role::User,
38            parts: vec![Part {
39                text: Some("Write a story about a magic backpack.".to_string()),
40                inline_data: None,
41                file_data: None,
42                video_metadata: None,
43            }],
44        }],
45        tools: vec![],
46        safety_settings: vec![],
47        generation_config: None,
48
49        #[cfg(feature = "beta")]
50        system_instruction: None,
51    };
52
53    let response = client.post(30, &txt_request).await?;
54
55    info!("{:#?}", response);
56
57    Ok(())
58}
More examples
Hide additional examples
examples/vertex_text_request.rs (lines 29-33)
24async fn main() -> Result<(), Box<dyn std::error::Error>> {
25    env_logger::init();
26    let region = env::var("GCP_REGION_NAME").unwrap().to_string();
27    let project_id = env::var("GCP_PROJECT_ID").unwrap().to_string();
28
29    let client = Client::new_from_region_project_id_response_type(
30        region.to_string(),
31        project_id.to_string(),
32        ResponseType::GenerateContent,
33    );
34
35    let txt_request = Request {
36        contents: vec![Content {
37            role: Role::User,
38            parts: vec![Part {
39                text: Some("Give me a recipe for banana bread.".to_string()),
40                inline_data: None,
41                file_data: None,
42                video_metadata: None,
43            }],
44        }],
45        tools: vec![],
46        safety_settings: vec![],
47        generation_config: None,
48
49        #[cfg(feature = "beta")]
50        system_instruction: None,
51    };
52
53    let response = client.post(30, &txt_request).await?;
54
55    info!("{:#?}", response);
56
57    Ok(())
58}
Source

pub fn new_from_model_region_project_id( model: Model, region: String, project_id: String, ) -> Self

Create a new private API client. Parameters:

  • model - the Gemini model to use
  • region - the GCP region to use
  • project_id - the GCP account project_id to use

Trait Implementations§

Source§

impl Display for Client

Ensuring there is no leakage of secrets

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnwindSafe for Client

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: 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,