bset

Macro bset 

Source
macro_rules! bset {
    (
    $( $key : expr ),* $( , )?
  ) => { ... };
}
Expand description

Creates a BTreeSet from a list of elements.

The bset macro allows for convenient creation of a BTreeSet with initial elements.

§Origin

This collection is reexported from alloc.

§Syntax

The macro can be called with a comma-separated list of elements. A trailing comma is optional.

// BTreeSet of &str
let set1 = bset!( "a", "b", "c" );

// With trailing comma
let set3 = bset!( 1, 2, 3, );

§Parameters

  • $( $key:expr ),* $( , )?: A comma-separated list of elements to insert into the BTreeSet. Each element can be of any type that implements the Into<T> trait, where T is the type stored in the BTreeSet.

§Returns

Returns a BTreeSet containing all the specified elements. The capacity of the set is automatically determined based on the number of elements provided.

§Example

Basic usage with string slices:

let set = bset!( "one", "two", "three" );
assert!( set.contains( "one" ) );
assert!( set.contains( "two" ) );
assert!( set.contains( "three" ) );
assert_eq!( set.len(), 3 );