Struct Env

Source
pub struct Env { /* private fields */ }

Implementations§

Source§

impl Env

Source

pub fn parse(content: &str) -> Vec<Hash>

It parse a env string Here’s a example

§Example
 use rust_env::{Env, Hash};

 let env: Vec<Hash> = Env::parse("PORT=6778\nHOST=127.0.0.1");
Source

pub fn marshal(val: Vec<Hash>) -> String

that will Marshal a piece of data like this

§Example
use rust_env::{Env, Hash, Str};

let d: Vec<Hash> = vec![
    Str("PORT", "6779")
];

assert_eq!(Env::marshal(d), "PORT=6779".to_string())
Source

pub fn new(name: &str) -> Env

New function create a new Env;

§Example
use rust_env::Env;
let env = Env::new("./.env");

//debug
env.debug();
Source

pub fn get_debug(self) -> Vec<Hash>

It will return the entire env local and global

§Example
use rust_env::{Env, Hash};

let env = Env::new("./.env");
let e: Vec<Hash> = env.get_debug();
Source

pub fn set(&mut self, h: Hash)

it will set a prop to your local env Here’s an example

§Example
use rust_env::{Env, Str, Wrapper};

let mut env = Env::new("./.env");
env.set(Str("PORT", "6778"));
Source

pub fn raw(&mut self, e: &str)

It’s similar to the set function But you’ll put raw string as parameter

§Example
use rust_env::Env;
use rust_env::Str;

let mut env = Env::new("./.env");
//Using set function
env.set(Str("PORT", "6778"));

//Using raw function
env.raw("PORT=6778");
Source

pub fn debug(&self)

It’s a function to debug the entire env

§Example
use rust_env::Env;
let env: Env = Env::new("./.env");

env.debug();
Source

pub fn upload(path: &str, pairs: Vec<Hash>) -> Env

You can # upload config data to a env file. It’s similar to the new function But you can write external data to the env file

§Example
use rust_env::{Env, Str, Vct};

let env = Env::upload("./env", vec![
      Str("PORT", "6778"),
      Vct("IP", vec![
         "127",
          "0",
          "0"
      ])
]);
Source

pub fn global_env(&mut self)

You can upload the global env data on the environment

§Example
 use rust_env::Env;

 let mut env: Env = Env::upload("./.env", vec![
     //put your local config
 ]);

 env.debug();
 env.global_env();
 env.debug();
Source

pub fn get_local(&self, k: &str) -> Wrapper

get_local is similar to get_hash But, You can just gt the local config Not the global

§Example
use rust_env::Wrapper;

let port = match get_local("PORT") {
    Wrapper::Str(v) => v,
    e => e
};
Source

pub fn get_global(&self, k: &str) -> Wrapper

get_global is similar to get_hash But, You can just gt the local config Not the global

§Example
use rust_env::Wrapper;

let path = match get_global("PATH") {
    Wrapper::Str(v) => v,
    e => e
};
Source

pub fn debug_global(&self)

It will print the global env

Source

pub fn debug_local(&self)

It will print the local env

§Example
use rust_env::Env;

let mut env = Env::new("./.env");
env.global_env();

//printing just global env
env.debug_global();

//printing just local env
env.debug_local()
Source

pub fn get_hash(&mut self, k: &str) -> Wrapper

You can get data from the Env

§Example
use rust_env::Wrapper;
let port = match env.get_hash("PORT") {
    Wrapper::Str(d) => d,
    _ => String::new()
};

let ip = match env.get_hash("IP") {
      Wrapper::Vec(v) => v,
      e => e
};

get_hash returns a Wrapper enum

Auto Trait Implementations§

§

impl Freeze for Env

§

impl RefUnwindSafe for Env

§

impl Send for Env

§

impl Sync for Env

§

impl Unpin for Env

§

impl UnwindSafe for Env

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.