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)>;
}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));