Skip to content

Commit

Permalink
add map and list creation functions to NifTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
hansihe committed May 15, 2017
1 parent b3088a8 commit a745af7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/types/list.rs
Expand Up @@ -131,6 +131,12 @@ impl<'a, T> NifEncoder for &'a [T] where T: NifEncoder {
/// ## List terms
impl<'a> NifTerm<'a> {

/// Returns a new empty list.
pub fn list_new_empty(env: NifEnv<'a>) -> NifTerm<'a> {
let list: &[u8] = &[];
list.encode(env)
}

/// Returns an iterator over a list term.
/// See documentation for NifListIterator for more information.
///
Expand Down
10 changes: 10 additions & 0 deletions src/types/map.rs
Expand Up @@ -10,6 +10,16 @@ pub fn map_new<'a>(env: NifEnv<'a>) -> NifTerm<'a> {
/// ## Map terms
impl<'a> NifTerm<'a> {

/// Constructs a new, empty map term.
///
/// ### Elixir equivalent
/// ```elixir
/// %{}
/// ```
pub fn map_new(env: NifEnv<'a>) -> NifTerm<'a> {
map_new(env)
}

/// Gets the value corresponding to a key in a map term.
///
/// Returns Err(NifError::BadArg) if the term is not a map or if
Expand Down

0 comments on commit a745af7

Please sign in to comment.