You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: state/src/path.rs
+45-3Lines changed: 45 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -132,6 +132,10 @@
132
132
//! }
133
133
//! }
134
134
//! ```
135
+
//!
136
+
//! # A note on availability
137
+
//!
138
+
//! Originally, these path handling features are also meant to be usable outside of the context of `save` and `restore`, for example to create a temporary audio file. However, the specification does not define whether the `FreePath` feature only deallocates the path string or if it deallocates the files pointed by the path too. Therefore, we can not guarantee that files and strings live outside of the scope of a trait function call and had to restrict the usage to `save` and `restore`.
135
139
usecrate::StateErr;
136
140
use lv2_core::feature::Feature;
137
141
use lv2_core::prelude::*;
@@ -145,7 +149,11 @@ use std::rc::Rc;
145
149
use std::sync::Mutex;
146
150
use urid::*;
147
151
148
-
/// A host feature to make absolute paths.
152
+
/// A host feature that allocates absolute file paths.
153
+
///
154
+
/// This is only useful in conjunction with the [`FreePath`](struct.FreePath.html) and [`MapPath`](struct.MapPath.html) features. Therefore, the interface of this feature is private and only exposed by a [`PathManager`](struct.PathManager.html), which is constructed from these three host features.
155
+
///
156
+
/// Please take a look at the [module documentation](index.html) for a usage example.
/// A host feature that maps absolute file paths to and from abstract file paths.
205
+
///
206
+
/// This is only useful in conjunction with the [`FreePath`](struct.FreePath.html) and [`MakePath`](struct.MakePath.html) features. Therefore, the interface of this feature is private and only exposed by a [`PathManager`](struct.PathManager.html), which is constructed from these three host features.
207
+
///
208
+
/// Please take a look at the [module documentation](index.html) for a usage example.
197
209
pubstructMapPath<'a>{
198
210
handle: sys::LV2_State_Map_Path_Handle,
199
211
abstract_path:unsafeextern"C"fn(
@@ -263,7 +275,11 @@ impl<'a> MapPath<'a> {
263
275
}
264
276
}
265
277
266
-
/// A host feature to a previously allocated path.
278
+
/// A host feature that deallocates absolute and abstract file paths.
279
+
///
280
+
/// This is only useful in conjunction with the [`MapPath`](struct.MapPath.html) and [`MakePath`](struct.MakePath.html) features. Therefore, the interface of this feature is private and only exposed by a [`PathManager`](struct.PathManager.html), which is constructed from these three host features.
281
+
///
282
+
/// Please take a look at the [module documentation](index.html) for a usage example.
/// An instance of this struct can be used just like a [`Path`](https://doc.rust-lang.org/stable/std/path/struct.Path.html) instance.
316
+
///
317
+
/// This path has been allocated by the host via a [`PathManager`](struct.PathManager.html) and will be deallocated by the host when dropped. Since it contains an `Rc<Mutex<>>`, it is neither `Send` nor `Sync` and shouldn't be used outside of the scope of a [`save`](../trait.State.html#tymethod.save) or [`restore`](../trait.State.html#tymethod.restore) call.
297
318
pubstructManagedPath<'a>{
298
319
path:&'aPath,
299
320
free_path:Rc<Mutex<FreePath<'a>>>,
@@ -322,6 +343,11 @@ impl<'a> Drop for ManagedPath<'a> {
322
343
}
323
344
}
324
345
346
+
/// A string that has been allocated by the host.
347
+
///
348
+
/// An instance of this struct can be used just like a [`str`](https://doc.rust-lang.org/stable/std/primitive.str.html) reference.
349
+
///
350
+
/// This string has been allocated by the host via a [`PathManager`](struct.PathManager.html) and will be deallocated by the host when dropped. Since it contains an `Rc<Mutex<>>`, it is neither `Send` nor `Sync` and shouldn't be used outside of the scope of a [`save`](../trait.State.html#tymethod.save) or [`restore`](../trait.State.html#tymethod.restore) call.
325
351
pubstructManagedStr<'a>{
326
352
str:&'astr,
327
353
free_path:Rc<Mutex<FreePath<'a>>>,
@@ -347,13 +373,19 @@ impl<'a> AsRef<str> for ManagedStr<'a> {
347
373
}
348
374
}
349
375
376
+
/// A safe interface to the path handling features.
377
+
///
378
+
/// This struct is constructed from the three path handling features, [`MakePath`](struct.MakePath.html), [`MapPath`](struct.MapPath.html), and [`FreePath`](struct.FreePath.html), and exposes them as one safe interface.
379
+
///
380
+
/// Please take a look at the [module documentation](index.html) for a usage example.
350
381
pubstructPathManager<'a>{
351
382
make:MakePath<'a>,
352
383
map:MapPath<'a>,
353
384
free:Rc<Mutex<FreePath<'a>>>,
354
385
}
355
386
356
387
impl<'a>PathManager<'a>{
388
+
/// Create a new path manager from the three path handling features.
/// This function maps the given relative file path to an absolute file path as well as an abstract file path. The absolute file path can be used to access the new file and the abstract file path is used to reference it in the state of the plugin. Storing the absolute file path in the plugin state will not work since it might have changed when the state is restored.
400
+
///
401
+
/// The relative file path will be the suffix of the absolute file path and will be contained in a namespace unique to the plugin instance. This means that allocations of the same relative path by different plugin instances will not collide. Apart from that, you can not make any other assumptions about the absolute and abstract file paths.
402
+
///
403
+
/// An abstract file path that has been read from the plugin state can be mapped back to an absolute file path with the [`deabstract_path`](#method.deabstract_path) method.
365
404
pubfnallocate_path(
366
405
&mutself,
367
406
relative_path:&Path,
@@ -385,6 +424,9 @@ impl<'a> PathManager<'a> {
385
424
Ok((absolute_path, abstract_path))
386
425
}
387
426
427
+
/// Map an abstract file path back to an absolute one.
428
+
///
429
+
/// After reading an abstract file path from the state, you have to map it back to an absolute file path in order to read the file. This is what this method does.
0 commit comments