[][src]Struct encon::Map

pub struct Map { /* fields omitted */ }

Represents a mapping of string keys to WithIntent values (a wrapper around Encryptable).

Example

use encon::Map;
use serde_json::json;
use serde_json::from_value;

let map: Map = from_value(json!({
   "k1": "foo",
   "k2": {
       "_encrypted": [
           "c10a4bed22a6511e0b6724f8c62832a6d85c154272b3b57a355568bb6af62ca99cc98e",
           "226163081382e58b796fc212e5427546aa9efb2923f561bc7e3b2418ec9166ea69309d",
           "aa0fee467e6ca538d9f7c29e"
        ]
    }
})).unwrap();

Implementations

impl Map[src]

pub fn new() -> Self[src]

Creates an empty Map

pub fn decrypt_all_in_place(
    &mut self,
    password: &Password
) -> Result<(), EnconError>
[src]

Attempts to decrypt all fields with the provided key. This does not change the intent of the fields. You may later call .apply_all_intents() to re-encrypt any keys that were originally encrypted; possibly with a different password.

pub fn apply_all_intents(
    &mut self,
    password: &Password
) -> Result<(), EnconError>
[src]

Applies the intended state of each field. See WithIntent::apply_intent for details.

pub fn to_json_pretty(&self) -> Result<String, MapToJsonError>[src]

Converts the Map to pretty-printed JSON.

This method requires that all intents have been applied (use apply_all_intents to accomplish this). If intents aren't applied, then Err(MapToJsonError::ApplyRequired) will be returned

pub fn to_json_compact(&self) -> Result<String, MapToJsonError>[src]

Similar to to_json_pretty, except printed as compactly as possible.

This is serde_json::to_string, but named explicitly since you usually want the to_json_pretty variant.

pub fn to_plain_map(&self, password: &Password) -> Result<PlainMap, EnconError>[src]

Decrypts all fields and returns a PlainMap containing them. This allows you to skip the plain vs encrypted checks in following code.

The method clones the keys/values because you may later want to apply changes to the PlainMap back on the Map, and then apply the original intents (which are only stored in Map).

pub fn insert(
    &mut self,
    key: impl Into<String>,
    value: impl Into<WithIntent>
) -> Option<WithIntent>
[src]

Insert a WithIntent/Encryptable, returning the existing WithIntent, if any.

pub fn insert_before(
    &mut self,
    index: usize,
    key: impl Into<String>,
    value: impl Into<WithIntent>
) -> Option<WithIntent>
[src]

Inserts the item before the specified index. If the index is >= the number of items, it's simply appended to the end.

use encon::Map;
use encon::Encryptable;

let mut map = Map::new();
map.insert("foo", encon::string("a"));
map.insert("baz", encon::string("c"));
map.insert_before(1, "bar", encon::string("b"));

let keys = map.keys().map(|k| k as &str).collect::<Vec<_>>();
assert_eq!(keys, vec!["foo", "bar", "baz"]);

pub fn keys(&self) -> impl Iterator<Item = &String>[src]

Return an iterator over the keys of the map, in their order

pub fn values(&self) -> impl Iterator<Item = &WithIntent>[src]

Return an iterator over the values of the map, in their order

pub fn entry(&mut self, key: String) -> Entry<'_, String, WithIntent>[src]

Get the given key’s corresponding entry in the map for insertion and/or in-place manipulation.

pub fn get(&self, key: impl Into<String>) -> Option<&WithIntent>[src]

Return a reference to the value stored for key, if it is present, else None.

pub fn get_mut(&mut self, key: impl Into<String>) -> Option<&mut WithIntent>[src]

Return a mutable reference to the value stored for key, if it is present, else None.

pub fn iter(&self) -> Iter<'_, String, WithIntent>[src]

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is (&'a String, &'a mut WithIntent)

pub fn iter_mut(&mut self) -> IterMut<'_, String, WithIntent>[src]

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is (&'a String, &'a mut WithIntent)

pub fn remove(&mut self, key: impl Into<String>) -> Option<WithIntent>[src]

Remove the entry for this key, and return it if it exists.

pub fn sort_keys(&mut self)[src]

Remove the entry for this key, and return it if it exists.

pub fn reverse(&mut self)[src]

pub fn len(&self) -> usize[src]

Returns the number of elements in the map.

pub fn is_empty(&self) -> bool[src]

Returns true if the map contains no elements.

Trait Implementations

impl Clone for Map[src]

impl Debug for Map[src]

impl Default for Map[src]

impl<'de> Deserialize<'de> for Map[src]

impl IntoIterator for Map[src]

type Item = (String, WithIntent)

The type of the elements being iterated over.

type IntoIter = IntoIter<String, WithIntent>

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a Map[src]

type Item = (&'a String, &'a WithIntent)

The type of the elements being iterated over.

type IntoIter = Iter<'a, String, WithIntent>

Which kind of iterator are we turning this into?

impl<'a> IntoIterator for &'a mut Map[src]

type Item = (&'a String, &'a mut WithIntent)

The type of the elements being iterated over.

type IntoIter = IterMut<'a, String, WithIntent>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl RefUnwindSafe for Map

impl Send for Map

impl Sync for Map

impl Unpin for Map

impl UnwindSafe for Map

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.