Skip to content

Commit cdf3ed1

Browse files
authored
feat: make some helpers/utils public (#316)
* feat: make `GetRange` helpers public * feat: make `GetOptions::check_precondition` public
1 parent 2c7b6d9 commit cdf3ed1

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ impl GetOptions {
976976
/// Returns an error if the modification conditions on this request are not satisfied
977977
///
978978
/// <https://datatracker.ietf.org/doc/html/rfc7232#section-6>
979-
fn check_preconditions(&self, meta: &ObjectMeta) -> Result<()> {
979+
pub fn check_preconditions(&self, meta: &ObjectMeta) -> Result<()> {
980980
// The use of the invalid etag "*" means no ETag is equivalent to never matching
981981
let etag = meta.e_tag.as_deref().unwrap_or("*");
982982
let last_modified = meta.last_modified;

src/util.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ pub enum GetRange {
208208
}
209209

210210
#[derive(Debug, thiserror::Error)]
211-
pub(crate) enum InvalidGetRange {
211+
#[non_exhaustive]
212+
pub enum InvalidGetRange {
212213
#[error("Wanted range starting at {requested}, but object was only {length} bytes long")]
213214
StartTooLarge { requested: u64, length: u64 },
214215

@@ -220,7 +221,8 @@ pub(crate) enum InvalidGetRange {
220221
}
221222

222223
impl GetRange {
223-
pub(crate) fn is_valid(&self) -> Result<(), InvalidGetRange> {
224+
/// Check if the range is valid.
225+
pub fn is_valid(&self) -> Result<(), InvalidGetRange> {
224226
if let Self::Bounded(r) = self {
225227
if r.end <= r.start {
226228
return Err(InvalidGetRange::Inconsistent {
@@ -238,8 +240,8 @@ impl GetRange {
238240
Ok(())
239241
}
240242

241-
/// Convert to a [`Range`] if valid.
242-
pub(crate) fn as_range(&self, len: u64) -> Result<Range<u64>, InvalidGetRange> {
243+
/// Convert to a [`Range`] if [valid](Self::is_valid).
244+
pub fn as_range(&self, len: u64) -> Result<Range<u64>, InvalidGetRange> {
243245
self.is_valid()?;
244246
match self {
245247
Self::Bounded(r) => {

0 commit comments

Comments
 (0)