204204//!
205205//! # Fetch objects
206206//!
207- //! Use the [`ObjectStore ::get`] method to fetch the data bytes
207+ //! Use the [`ObjectStoreExt ::get`] / [`ObjectStore::get_opts `] method to fetch the data bytes
208208//! from remote storage or files in the local filesystem as a stream.
209209//!
210210//! ```ignore-wasm32
211211//! # use futures::TryStreamExt;
212212//! # use object_store::local::LocalFileSystem;
213213//! # use std::sync::Arc;
214214//! # use bytes::Bytes;
215- //! # use object_store::{path::Path, ObjectStore, GetResult};
215+ //! # use object_store::{path::Path, ObjectStore, ObjectStoreExt, GetResult};
216216//! # fn get_object_store() -> Arc<dyn ObjectStore> {
217217//! # Arc::new(LocalFileSystem::new())
218218//! # }
403403//! ```
404404//! # use std::collections::btree_map::Entry;
405405//! # use std::collections::HashMap;
406- //! # use object_store::{GetOptions, GetResult, ObjectStore, Result, Error};
406+ //! # use object_store::{GetOptions, GetResult, ObjectStore, ObjectStoreExt, Result, Error};
407407//! # use std::sync::Arc;
408408//! # use std::time::{Duration, Instant};
409409//! # use bytes::Bytes;
468468//! storage, without relying on a separate DBMS.
469469//!
470470//! ```
471- //! # use object_store::{Error, ObjectStore, PutMode, UpdateVersion};
471+ //! # use object_store::{Error, ObjectStore, ObjectStoreExt, PutMode, UpdateVersion};
472472//! # use std::sync::Arc;
473473//! # use bytes::Bytes;
474474//! # use tokio::io::AsyncWriteExt;
@@ -651,38 +651,6 @@ pub trait ObjectStore: std::fmt::Display + Send + Sync + Debug + 'static {
651651 opts : PutMultipartOptions ,
652652 ) -> Result < Box < dyn MultipartUpload > > ;
653653
654- /// Return the bytes that are stored at the specified location.
655- ///
656- /// ## Example
657- ///
658- /// This example uses a basic local filesystem object store to get an object.
659- ///
660- /// ```ignore-wasm32
661- /// # use object_store::local::LocalFileSystem;
662- /// # use tempfile::tempdir;
663- /// # use object_store::{path::Path, ObjectStore, ObjectStoreExt};
664- /// async fn get_example() {
665- /// let tmp = tempdir().unwrap();
666- /// let store = LocalFileSystem::new_with_prefix(tmp.path()).unwrap();
667- /// let location = Path::from("example.txt");
668- /// let content = b"Hello, Object Store!";
669- ///
670- /// // Put the object into the store
671- /// store
672- /// .put(&location, content.as_ref().into())
673- /// .await
674- /// .expect("Failed to put object");
675- ///
676- /// // Get the object from the store
677- /// let get_result = store.get(&location).await.expect("Failed to get object");
678- /// let bytes = get_result.bytes().await.expect("Failed to read bytes");
679- /// println!("Retrieved content: {}", String::from_utf8_lossy(&bytes));
680- /// }
681- /// ```
682- async fn get ( & self , location : & Path ) -> Result < GetResult > {
683- self . get_opts ( location, GetOptions :: default ( ) ) . await
684- }
685-
686654 /// Perform a get request with options
687655 ///
688656 /// ## Example
@@ -1115,10 +1083,6 @@ macro_rules! as_ref_impl {
11151083 self . as_ref( ) . put_multipart_opts( location, opts) . await
11161084 }
11171085
1118- async fn get( & self , location: & Path ) -> Result <GetResult > {
1119- self . as_ref( ) . get( location) . await
1120- }
1121-
11221086 async fn get_opts( & self , location: & Path , options: GetOptions ) -> Result <GetResult > {
11231087 self . as_ref( ) . get_opts( location, options) . await
11241088 }
@@ -1212,6 +1176,36 @@ pub trait ObjectStoreExt: ObjectStore {
12121176 & self ,
12131177 location : & Path ,
12141178 ) -> impl Future < Output = Result < Box < dyn MultipartUpload > > > ;
1179+
1180+ /// Return the bytes that are stored at the specified location.
1181+ ///
1182+ /// ## Example
1183+ ///
1184+ /// This example uses a basic local filesystem object store to get an object.
1185+ ///
1186+ /// ```ignore-wasm32
1187+ /// # use object_store::local::LocalFileSystem;
1188+ /// # use tempfile::tempdir;
1189+ /// # use object_store::{path::Path, ObjectStore, ObjectStoreExt};
1190+ /// async fn get_example() {
1191+ /// let tmp = tempdir().unwrap();
1192+ /// let store = LocalFileSystem::new_with_prefix(tmp.path()).unwrap();
1193+ /// let location = Path::from("example.txt");
1194+ /// let content = b"Hello, Object Store!";
1195+ ///
1196+ /// // Put the object into the store
1197+ /// store
1198+ /// .put(&location, content.as_ref().into())
1199+ /// .await
1200+ /// .expect("Failed to put object");
1201+ ///
1202+ /// // Get the object from the store
1203+ /// let get_result = store.get(&location).await.expect("Failed to get object");
1204+ /// let bytes = get_result.bytes().await.expect("Failed to read bytes");
1205+ /// println!("Retrieved content: {}", String::from_utf8_lossy(&bytes));
1206+ /// }
1207+ /// ```
1208+ fn get ( & self , location : & Path ) -> impl Future < Output = Result < GetResult > > ;
12151209}
12161210
12171211impl < T > ObjectStoreExt for T
@@ -1227,6 +1221,10 @@ where
12271221 self . put_multipart_opts ( location, PutMultipartOptions :: default ( ) )
12281222 . await
12291223 }
1224+
1225+ async fn get ( & self , location : & Path ) -> Result < GetResult > {
1226+ self . get_opts ( location, GetOptions :: default ( ) ) . await
1227+ }
12301228}
12311229
12321230/// Result of a list call that includes objects, prefixes (directories) and a
0 commit comments