pub struct Env { /* private fields */ }
Implementations§
Source§impl Env
impl Env
Sourcepub fn parse(content: &str) -> Vec<Hash>
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");
Sourcepub fn marshal(val: Vec<Hash>) -> String
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())
Sourcepub fn new(name: &str) -> Env
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();
Sourcepub fn get_debug(self) -> Vec<Hash>
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();
Sourcepub fn set(&mut self, h: Hash)
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"));
Sourcepub fn raw(&mut self, e: &str)
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");
Sourcepub fn debug(&self)
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();
Sourcepub fn upload(path: &str, pairs: Vec<Hash>) -> Env
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"
])
]);
Sourcepub fn global_env(&mut self)
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();
Sourcepub fn get_local(&self, k: &str) -> Wrapper
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
};
Sourcepub fn get_global(&self, k: &str) -> Wrapper
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
};
Sourcepub fn debug_global(&self)
pub fn debug_global(&self)
It will print the global env
Sourcepub fn debug_local(&self)
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()
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more