pub enum IndexType {
Ordered(Order),
Text,
Hashed,
Geo2D,
Geo2DSphere,
GeoHaystack,
}
An index type, applied to a single indexed field.
let patient_index = doc!{
"description": IndexType::Text,
"body.mass": IndexType::Ordered(Order::Ascending),
"birth_date.year": IndexType::Ordered(Order::Descending),
"address_gps_coords": IndexType::Geo2DSphere,
};
assert_eq!(patient_index, doc!{
"description": "text",
"body.mass": 1,
"birth_date.year": -1,
"address_gps_coords": "2dsphere",
});
A language-specific textual index, most useful for freetext searches.
Hashed index for hash-based sharding.
2D geospatial index with planar (Euclidean) geometry.
2D geospatial index with spherical geometry.
2D geospatial index optimized for very small areas.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
let asc_i32 = Bson::I32(1);
let desc_i64 = Bson::I64(-1);
let asc_float = Bson::FloatingPoint(1.0);
let text = Bson::from("text");
let spherical_2d = Bson::from("2dsphere");
let hashed = Bson::from("hashed");
let bad_i64 = Bson::I64(0);
let bad_float = Bson::FloatingPoint(3.14);
let bad_str = Bson::from("Ascending");
let bad_type = Bson::Boolean(true);
assert_eq!(from_bson::<IndexType>(asc_i32)?,
IndexType::Ordered(Order::Ascending));
assert_eq!(from_bson::<IndexType>(desc_i64)?,
IndexType::Ordered(Order::Descending));
assert_eq!(from_bson::<IndexType>(asc_float)?,
IndexType::Ordered(Order::Ascending));
assert_eq!(from_bson::<IndexType>(text)?,
IndexType::Text);
assert_eq!(from_bson::<IndexType>(spherical_2d)?,
IndexType::Geo2DSphere);
assert_eq!(from_bson::<IndexType>(hashed)?,
IndexType::Hashed);
assert!(from_bson::<IndexType>(bad_i64)
.unwrap_err()
.to_string()
.contains("invalid ordering"));
assert!(from_bson::<IndexType>(bad_float)
.unwrap_err()
.to_string()
.contains("invalid ordering"));
assert!(from_bson::<IndexType>(bad_str)
.unwrap_err()
.to_string()
.contains("unrecognized index type"));
assert!(from_bson::<IndexType>(bad_type)
.unwrap_err()
.to_string()
.contains("an ordering integer or an index type string"));
Deserialize this value from the given Serde deserializer. Read more
let asc = IndexType::Ordered(Order::Ascending);
let desc = IndexType::Ordered(Order::Descending);
let haystack = IndexType::GeoHaystack;
let text = IndexType::Text;
let planar_2d = IndexType::Geo2D;
let spherical_2d = IndexType::Geo2DSphere;
assert_eq!(to_bson(&asc)?, Bson::from(asc));
assert_eq!(to_bson(&desc)?, Bson::from(desc));
assert_eq!(to_bson(&haystack)?, Bson::from(haystack));
assert_eq!(to_bson(&text)?, Bson::from(text));
assert_eq!(to_bson(&planar_2d)?, Bson::from(planar_2d));
assert_eq!(to_bson(&spherical_2d)?, Bson::from(spherical_2d));
Serialize this value into the given Serde serializer. Read more
Creates owned data from borrowed data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
impl<T, U> TryInto for T where U: TryFrom<T>, | |
type Err = <U as TryFrom<T>>::Err