Skip to content

Commit 41ca3a4

Browse files
committed
feat: implement GetOptions extensions
1 parent 2c84f24 commit 41ca3a4

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

object_store/src/extensions.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use std::{
2+
any::{Any, TypeId},
3+
collections::HashMap,
4+
sync::Arc,
5+
};
6+
7+
type ExtensionMap = HashMap<TypeId, Ext>;
8+
type Ext = Arc<dyn Any + Send + Sync + 'static>;
9+
10+
#[derive(Debug, Default, Clone)]
11+
pub struct Extensions {
12+
inner: ExtensionMap,
13+
}
14+
15+
impl Extensions {
16+
fn set_ext<T: Send + Sync + 'static>(&mut self, t: T) {
17+
let id = t.type_id();
18+
let a = Arc::new(t);
19+
self.inner.insert(id, a);
20+
}
21+
22+
fn get_ext<T: Send + Sync + 'static>(&self) -> Option<Arc<T>> {
23+
let id = TypeId::of::<T>();
24+
self.inner
25+
.get(&id)
26+
.cloned()
27+
.map(|e| Arc::downcast(e).expect("TypeId is always unique"))
28+
}
29+
}
30+
31+
impl From<HashMap<TypeId, Ext>> for Extensions {
32+
fn from(inner: HashMap<TypeId, Ext>) -> Self {
33+
Self { inner }
34+
}
35+
}

object_store/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ mod config;
536536

537537
mod tags;
538538

539+
pub use extensions::Extensions;
539540
pub use tags::TagSet;
540541

541542
pub mod multipart;
@@ -545,6 +546,7 @@ mod upload;
545546
mod util;
546547

547548
mod attributes;
549+
mod extensions;
548550

549551
#[cfg(any(feature = "integration", test))]
550552
pub mod integration;
@@ -910,7 +912,6 @@ pub struct ObjectMeta {
910912
/// A version indicator for this object
911913
pub version: Option<String>,
912914
}
913-
914915
/// Options for a get request, such as range
915916
#[derive(Debug, Default, Clone)]
916917
pub struct GetOptions {
@@ -963,6 +964,13 @@ pub struct GetOptions {
963964
///
964965
/// <https://datatracker.ietf.org/doc/html/rfc9110#name-head>
965966
pub head: bool,
967+
968+
/// Implementation-specific extensions. but
969+
/// intended for use by [`ObjectStore`] implementations that need to pass context-specific
970+
/// information (like tracing spans) via trait methods.
971+
///
972+
/// These extensions are ignored entirely by backends offered through this crate.
973+
pub extensions: Extensions,
966974
}
967975

968976
impl GetOptions {

0 commit comments

Comments
 (0)