pub struct Documents(/* private fields */);
Implementations§
Source§impl Documents
impl Documents
pub fn new() -> Self
pub async fn handle_open_file(&self, uri: &Url)
Sourcepub async fn write_changes_to_file(
&self,
uri: &Url,
changes: &[TextDocumentContentChangeEvent],
) -> Result<(), LanguageServerError>
pub async fn write_changes_to_file( &self, uri: &Url, changes: &[TextDocumentContentChangeEvent], ) -> Result<(), LanguageServerError>
Asynchronously writes the changes to the file and updates the document.
Sourcepub fn update_text_document(
&self,
uri: &Url,
changes: &[TextDocumentContentChangeEvent],
) -> Result<String, DocumentError>
pub fn update_text_document( &self, uri: &Url, changes: &[TextDocumentContentChangeEvent], ) -> Result<String, DocumentError>
Update the document at the given Url with the Vec of changes returned by the client.
Sourcepub fn get_text_document(
&self,
url: &Url,
) -> Result<TextDocument, DocumentError>
pub fn get_text_document( &self, url: &Url, ) -> Result<TextDocument, DocumentError>
Get the document at the given Url.
Sourcepub fn remove_document(&self, url: &Url) -> Result<TextDocument, DocumentError>
pub fn remove_document(&self, url: &Url) -> Result<TextDocument, DocumentError>
Remove the text document.
Sourcepub fn store_document(
&self,
text_document: TextDocument,
) -> Result<(), DocumentError>
pub fn store_document( &self, text_document: TextDocument, ) -> Result<(), DocumentError>
Store the text document.
Methods from Deref<Target = DashMap<String, TextDocument>>§
Sourcepub fn hash_usize<T>(&self, item: &T) -> usizewhere
T: Hash,
pub fn hash_usize<T>(&self, item: &T) -> usizewhere
T: Hash,
Hash a given item to produce a usize. Uses the provided or default HashBuilder.
Sourcepub fn hasher(&self) -> &S
pub fn hasher(&self) -> &S
Returns a reference to the map’s BuildHasher
.
§Examples
use dashmap::DashMap;
use std::collections::hash_map::RandomState;
let hasher = RandomState::new();
let map: DashMap<i32, i32> = DashMap::new();
let hasher: &RandomState = map.hasher();
Sourcepub fn insert(&self, key: K, value: V) -> Option<V>
pub fn insert(&self, key: K, value: V) -> Option<V>
Inserts a key and a value into the map. Returns the old value associated with the key if there was one.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let map = DashMap::new();
map.insert("I am the key!", "And I am the value!");
Sourcepub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
pub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
Removes an entry from the map, returning the key and value if they existed in the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let soccer_team = DashMap::new();
soccer_team.insert("Jack", "Goalie");
assert_eq!(soccer_team.remove("Jack").unwrap().1, "Goalie");
Sourcepub fn remove_if<Q>(
&self,
key: &Q,
f: impl FnOnce(&K, &V) -> bool,
) -> Option<(K, V)>
pub fn remove_if<Q>( &self, key: &Q, f: impl FnOnce(&K, &V) -> bool, ) -> Option<(K, V)>
Removes an entry from the map, returning the key and value if the entry existed and the provided conditional function returned true.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
use dashmap::DashMap;
let soccer_team = DashMap::new();
soccer_team.insert("Sam", "Forward");
soccer_team.remove_if("Sam", |_, position| position == &"Goalie");
assert!(soccer_team.contains_key("Sam"));
use dashmap::DashMap;
let soccer_team = DashMap::new();
soccer_team.insert("Sam", "Forward");
soccer_team.remove_if("Sam", |_, position| position == &"Forward");
assert!(!soccer_team.contains_key("Sam"));
pub fn remove_if_mut<Q>( &self, key: &Q, f: impl FnOnce(&K, &mut V) -> bool, ) -> Option<(K, V)>
Sourcepub fn iter(&'a self) -> Iter<'a, K, V, S>
pub fn iter(&'a self) -> Iter<'a, K, V, S>
Creates an iterator over a DashMap yielding immutable references.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let words = DashMap::new();
words.insert("hello", "world");
assert_eq!(words.iter().count(), 1);
Sourcepub fn iter_mut(&'a self) -> IterMut<'a, K, V, S>
pub fn iter_mut(&'a self) -> IterMut<'a, K, V, S>
Iterator over a DashMap yielding mutable references.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let map = DashMap::new();
map.insert("Johnny", 21);
map.iter_mut().for_each(|mut r| *r += 1);
assert_eq!(*map.get("Johnny").unwrap(), 22);
Sourcepub fn get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V>>
pub fn get<Q>(&'a self, key: &Q) -> Option<Ref<'a, K, V>>
Get an immutable reference to an entry in the map
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let youtubers = DashMap::new();
youtubers.insert("Bosnian Bill", 457000);
assert_eq!(*youtubers.get("Bosnian Bill").unwrap(), 457000);
Sourcepub fn get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V>>
pub fn get_mut<Q>(&'a self, key: &Q) -> Option<RefMut<'a, K, V>>
Get a mutable reference to an entry in the map
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let class = DashMap::new();
class.insert("Albin", 15);
*class.get_mut("Albin").unwrap() -= 1;
assert_eq!(*class.get("Albin").unwrap(), 14);
Sourcepub fn try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V>>
pub fn try_get<Q>(&'a self, key: &Q) -> TryResult<Ref<'a, K, V>>
Get an immutable reference to an entry in the map, if the shard is not locked. If the shard is locked, the function will return TryResult::Locked.
§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;
let map = DashMap::new();
map.insert("Johnny", 21);
assert_eq!(*map.try_get("Johnny").unwrap(), 21);
let _result1_locking = map.get_mut("Johnny");
let result2 = map.try_get("Johnny");
assert!(result2.is_locked());
Sourcepub fn try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V>>
pub fn try_get_mut<Q>(&'a self, key: &Q) -> TryResult<RefMut<'a, K, V>>
Get a mutable reference to an entry in the map, if the shard is not locked. If the shard is locked, the function will return TryResult::Locked.
§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;
let map = DashMap::new();
map.insert("Johnny", 21);
*map.try_get_mut("Johnny").unwrap() += 1;
assert_eq!(*map.get("Johnny").unwrap(), 22);
let _result1_locking = map.get("Johnny");
let result2 = map.try_get_mut("Johnny");
assert!(result2.is_locked());
Sourcepub fn shrink_to_fit(&self)
pub fn shrink_to_fit(&self)
Remove excess capacity to reduce memory usage.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
use dashmap::try_result::TryResult;
let map = DashMap::new();
map.insert("Johnny", 21);
assert!(map.capacity() > 0);
map.remove("Johnny");
map.shrink_to_fit();
assert_eq!(map.capacity(), 0);
Sourcepub fn retain(&self, f: impl FnMut(&K, &mut V) -> bool)
pub fn retain(&self, f: impl FnMut(&K, &mut V) -> bool)
Retain elements that whose predicates return true and discard elements whose predicates return false.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let people = DashMap::new();
people.insert("Albin", 15);
people.insert("Jones", 22);
people.insert("Charlie", 27);
people.retain(|_, v| *v > 20);
assert_eq!(people.len(), 2);
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Fetches the total number of key-value pairs stored in the map.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let people = DashMap::new();
people.insert("Albin", 15);
people.insert("Jones", 22);
people.insert("Charlie", 27);
assert_eq!(people.len(), 3);
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the map is empty or not.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let map = DashMap::<(), ()>::new();
assert!(map.is_empty());
Sourcepub fn clear(&self)
pub fn clear(&self)
Removes all key-value pairs in the map.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let stats = DashMap::new();
stats.insert("Goals", 4);
assert!(!stats.is_empty());
stats.clear();
assert!(stats.is_empty());
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns how many key-value pairs the map can store without reallocating.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
Sourcepub fn alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
pub fn alter<Q>(&self, key: &Q, f: impl FnOnce(&K, V) -> V)
Modify a specific value according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let stats = DashMap::new();
stats.insert("Goals", 4);
stats.alter("Goals", |_, v| v * 2);
assert_eq!(*stats.get("Goals").unwrap(), 8);
§Panics
If the given closure panics, then alter
will abort the process
Sourcepub fn alter_all(&self, f: impl FnMut(&K, V) -> V)
pub fn alter_all(&self, f: impl FnMut(&K, V) -> V)
Modify every value in the map according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let stats = DashMap::new();
stats.insert("Wins", 4);
stats.insert("Losses", 2);
stats.alter_all(|_, v| v + 1);
assert_eq!(*stats.get("Wins").unwrap(), 5);
assert_eq!(*stats.get("Losses").unwrap(), 3);
§Panics
If the given closure panics, then alter_all
will abort the process
Sourcepub fn view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
pub fn view<Q, R>(&self, key: &Q, f: impl FnOnce(&K, &V) -> R) -> Option<R>
Scoped access into an item of the map according to a function.
Locking behaviour: May deadlock if called when holding any sort of reference into the map.
§Examples
use dashmap::DashMap;
let warehouse = DashMap::new();
warehouse.insert(4267, ("Banana", 100));
warehouse.insert(2359, ("Pear", 120));
let fruit = warehouse.view(&4267, |_k, v| *v);
assert_eq!(fruit, Some(("Banana", 100)));
§Panics
If the given closure panics, then view
will abort the process
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Checks if the map contains a specific key.
Locking behaviour: May deadlock if called when holding a mutable reference into the map.
§Examples
use dashmap::DashMap;
let team_sizes = DashMap::new();
team_sizes.insert("Dakota Cherries", 23);
assert!(team_sizes.contains_key("Dakota Cherries"));
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Documents
impl !RefUnwindSafe for Documents
impl Send for Documents
impl Sync for Documents
impl Unpin for Documents
impl UnwindSafe for Documents
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> StorageAsMut for T
impl<T> StorageAsMut for T
fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where
Type: Mappable,
Source§impl<T> StorageAsRef for T
impl<T> StorageAsRef for T
fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where
Type: Mappable,
fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>where
Type: Mappable,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.