[−][src]Function simplelock::default_lock
pub fn default_lock(
app_name: impl Into<String>
) -> SimpleLockResult<Box<dyn Lock>>
Get a lock with default configuration based on the feature enabled.
Two calls to this function, with the same argument, will provide unique objects but
will describe the same lock. For example, if the file
feature is enabled, this will
return a unique FileLock
. However, they will both point to the same file, and thus
lock operations on these objects will be in competition.
Note: If multiple features are enabled at once, we make no guarantees on the type of lock returned. Internally though, we try to return the ones we have the strongest guarantees around based on the OS. If you want consistency, either enable a single feature or call the constructor needed directly.
Examples
To enable FileLock
by default, add this to your Cargo.toml:
[dependencies]
simplelock = { version = "*", features = [ "file" ] }
Then you can create a file lock in a general way like so:
let mut lock = default_lock("MyAppName")?; // Do something with the lock!