pub trait ObjectStoreRegistry:
Send
+ Sync
+ Debug
+ 'static {
// Required methods
fn register(
&self,
url: Url,
store: Arc<dyn ObjectStore>,
) -> Option<Arc<dyn ObjectStore>>;
fn resolve(&self, url: &Url) -> Result<(Arc<dyn ObjectStore>, Path)>;
// Provided method
fn deregister(&self, url: &Url) -> Option<Arc<dyn ObjectStore>> { ... }
}Expand description
ObjectStoreRegistry maps a URL to an ObjectStore instance
Required Methods§
Sourcefn register(
&self,
url: Url,
store: Arc<dyn ObjectStore>,
) -> Option<Arc<dyn ObjectStore>>
fn register( &self, url: Url, store: Arc<dyn ObjectStore>, ) -> Option<Arc<dyn ObjectStore>>
Register a new store for the provided store URL
If a store with the same URL existed before, it is replaced and returned
Sourcefn resolve(&self, url: &Url) -> Result<(Arc<dyn ObjectStore>, Path)>
fn resolve(&self, url: &Url) -> Result<(Arc<dyn ObjectStore>, Path)>
Resolve an object URL
If ObjectStoreRegistry::register has been called with a URL with the same
scheme, and authority as the object URL, and a path that is a prefix of the object
URL’s, it should be returned along with the trailing path. Paths should be matched
on a path segment basis, and in the event of multiple possibilities the longest
path match should be returned.
If a store hasn’t been registered, an ObjectStoreRegistry may lazily create
one if the URL is understood
For example
let registry = DefaultObjectStoreRegistry::new();
let bucket1 = Arc::new(InMemory::new()) as Arc<dyn ObjectStore>;
let base = Url::parse("s3://bucket1/").unwrap();
registry.register(base, bucket1.clone());
let url = Url::parse("s3://bucket1/path/to/object").unwrap();
let (ret, path) = registry.resolve(&url).unwrap();
assert_eq!(path.as_ref(), "path/to/object");
assert!(Arc::ptr_eq(&ret, &bucket1));
let bucket2 = Arc::new(InMemory::new()) as Arc<dyn ObjectStore>;
let base = Url::parse("https://s3.region.amazonaws.com/bucket").unwrap();
registry.register(base, bucket2.clone());
let url = Url::parse("https://s3.region.amazonaws.com/bucket/path/to/object").unwrap();
let (ret, path) = registry.resolve(&url).unwrap();
assert_eq!(path.as_ref(), "path/to/object");
assert!(Arc::ptr_eq(&ret, &bucket2));
let bucket3 = Arc::new(PrefixStore::new(InMemory::new(), "path")) as Arc<dyn ObjectStore>;
let base = Url::parse("https://s3.region.amazonaws.com/bucket/path").unwrap();
registry.register(base, bucket3.clone());
let url = Url::parse("https://s3.region.amazonaws.com/bucket/path/to/object").unwrap();
let (ret, path) = registry.resolve(&url).unwrap();
assert_eq!(path.as_ref(), "to/object");
assert!(Arc::ptr_eq(&ret, &bucket3));Provided Methods§
Sourcefn deregister(&self, url: &Url) -> Option<Arc<dyn ObjectStore>>
fn deregister(&self, url: &Url) -> Option<Arc<dyn ObjectStore>>
Deregister the store registered for exactly url, returning it if present.
Unlike resolve, which matches the longest registered
path that is a prefix of the object URL, this removes the store
registered at the exact scheme, authority and path of url (the
inverse of register). A store registered at a
different path under the same authority is left in place.
The default implementation does nothing and returns None.
let registry = DefaultObjectStoreRegistry::new();
let bucket = Arc::new(InMemory::new()) as Arc<dyn ObjectStore>;
let url = Url::parse("s3://bucket/path").unwrap();
registry.register(url.clone(), bucket.clone());
let removed = registry.deregister(&url).unwrap();
assert!(Arc::ptr_eq(&removed, &bucket));Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".