Process

Struct Process 

Source
pub struct Process;
Expand description

Utilities for managing process-level operations.

Implementations§

Source§

impl Process

Source

pub fn args() -> Vec<String>

Returns a vector of command-line arguments passed to the program.

§Examples
use seda_sdk_rs::process::Process;

let args = Process::args();
// args[0] is the program name
// args[1] would be the first argument
Source

pub fn envs() -> BTreeMap<String, String>

Returns a map of all environment variables.

§Examples
use seda_sdk_rs::process::Process;

std::env::set_var("TEST_VAR", "test_value");

let env_vars = Process::envs();
assert!(env_vars.contains_key("TEST_VAR"));
for (key, value) in env_vars {
    println!("{}: {}", key, value);
}
Source

pub fn get_inputs() -> Vec<u8>

Retrieves and decodes the data request inputs

§Panics

This function will panic if:

  • There were no arguments passed to the program.
  • The second argument (index 1) is not a valid hex string.
§Examples
use seda_sdk_rs::process::Process;

let input_bytes = Process::get_inputs();
// Process the input bytes...
Source

pub fn is_tally_vm_mode() -> bool

Checks if the current VM mode is set to tally mode.

§Examples
use seda_sdk_rs::process::Process;

std::env::set_var("VM_MODE", "tally");
if Process::is_tally_vm_mode() {
    // Handle tally mode specific logic
}
Source

pub fn is_dr_vm_mode() -> bool

Checks if the current VM mode is set to DR mode.

§Examples
use seda_sdk_rs::process::Process;

if Process::is_dr_vm_mode() {
    let replication = Process::replication_factor();
    // Handle DR mode specific logic
}
Source

pub fn success(result: &[u8]) -> !

Exits the process successfully (code 0) with the given result.

§Examples
use seda_sdk_rs::process::Process;

let result = vec![0x01, 0x02, 0x03];
Process::success(&result);
Source

pub fn error(result: &[u8]) -> !

Exits the process with an error (code 1) and the given result.

§Examples
use seda_sdk_rs::process::Process;

let error_data = vec![0xFF];
Process::error(&error_data);
Source

pub fn replication_factor() -> u16

Gets the replication factor for the data request

§Panics

This function will panic if:

  • The DR_REPLICATION_FACTOR_ENV_KEY environment variable is not set.
  • The value of DR_REPLICATION_FACTOR_ENV_KEY is not a valid u16.

These conditions should never happen in a properly configured environment.

§Examples
use seda_sdk_rs::process::Process;

if Process::is_dr_vm_mode() {
    let factor = Process::replication_factor();
    println!("Replication factor: {}", factor);
}
Source

pub fn exit_with_message(code: u8, message: &str) -> !

Exits the process with the given code and message.

§Examples
use seda_sdk_rs::process::Process;

// Exit with an error message
Process::exit_with_message(1, "Operation failed: invalid input");

// Exit with success message
Process::exit_with_message(0, "Operation completed successfully");
Source

pub fn exit_with_result(code: u8, result: &[u8]) -> !

Exits the process with the given code and result bytes.

§Examples
use seda_sdk_rs::process::Process;

let result = vec![1, 2, 3, 4];
Process::exit_with_result(0, &result);
Source

pub fn exit(code: u8) -> !

Exits the process with the given code and an empty result.

§Examples
use seda_sdk_rs::process::Process;

// Exit successfully with no result
Process::exit(0);

// Exit with error code
Process::exit(1);

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, 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, 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.