Context

Struct Context 

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

Context provides the context for the request signing.

§Important

reqsign provides NO default implementations. Users MAY configure components they need. Any unconfigured component will use a no-op implementation that returns errors or empty values when called.

§Example

use reqsign_core::{Context, OsEnv};

// Create a context with explicit implementations
let ctx = Context::new()
    .with_env(OsEnv);  // Optionally configure environment implementation

Implementations§

Source§

impl Context

Source

pub fn new() -> Self

Create a new Context with no-op implementations.

All components use no-op implementations by default. Use the with_* methods to configure the components you need.

use reqsign_core::Context;

let ctx = Context::new();
// All components use no-op implementations by default
// You can configure specific components as needed:
// ctx.with_file_read(my_file_reader)
//    .with_http_send(my_http_client)
//    .with_env(my_env_provider);
Source

pub fn with_file_read(self, fs: impl FileRead) -> Self

Replace the file reader implementation.

Source

pub fn with_http_send(self, http: impl HttpSend) -> Self

Replace the HTTP client implementation.

Source

pub fn with_env(self, env: impl Env) -> Self

Replace the environment implementation.

Source

pub fn with_command_execute(self, cmd: impl CommandExecute) -> Self

Replace the command executor implementation.

Source

pub async fn file_read(&self, path: &str) -> Result<Vec<u8>>

Read the file content entirely in Vec<u8>.

Source

pub async fn file_read_as_string(&self, path: &str) -> Result<String>

Read the file content entirely in String.

Source

pub async fn http_send(&self, req: Request<Bytes>) -> Result<Response<Bytes>>

Send http request and return the response.

Source

pub async fn http_send_as_string( &self, req: Request<Bytes>, ) -> Result<Response<String>>

Send http request and return the response as string.

Source

pub fn home_dir(&self) -> Option<PathBuf>

Get the home directory of the current user.

Source

pub fn expand_home_dir(&self, path: &str) -> Option<String>

Expand ~ in input path.

  • If path not starts with ~/ or ~\\, returns Some(path) directly.
  • Otherwise, replace ~ with home dir instead.
  • If home_dir is not found, returns None.
Source

pub fn env_var(&self, key: &str) -> Option<String>

Get the environment variable.

  • Returns Some(v) if the environment variable is found and is valid utf-8.
  • Returns None if the environment variable is not found or value is invalid.
Source

pub fn env_vars(&self) -> HashMap<String, String>

Returns a hashmap of (variable, value) pairs of strings, for all the environment variables of the current process.

Source

pub async fn command_execute( &self, program: &str, args: &[&str], ) -> Result<CommandOutput>

Execute an external command with the given program and arguments.

Returns the command output including exit status, stdout, and stderr.

Trait Implementations§

Source§

impl Clone for Context

Source§

fn clone(&self) -> Context

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 Context

Source§

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

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

impl Default for Context

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.