Skip to content

Commit

Permalink
Merge branch 'release/v0.5.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
lo48576 committed Jun 19, 2022
2 parents dc58f89 + d5b441c commit e7a93f3
Show file tree
Hide file tree
Showing 19 changed files with 2,864 additions and 793 deletions.
38 changes: 36 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@

## [Unreleased]

## [0.5.6]

* Fix normalization bug.
+ Previously, trailing colon of an authority (with empty port) was not
stripped. Now this is fixed.
* Add `ensure_rfc3986_normalizable()` methods to absolute IRI string types.
* Add IRI builder in `build` module.
* Deprecate `percent_encoding` module in favor of the new name `percent_encode`.

### Added
* Add `ensure_rfc3986_normalizable()` methods to absolute IRI string types.
+ List of added functions:
- `types::RiStr::ensure_rfc3986_normalizable()`
- `types::RiAbsoluteStr::ensure_rfc3986_normalizable()`
* Add IRI builder in `build` module.
+ `Builder` type is a builder.
+ `DisplayBulid` type is a validated build result (but not yet heap-allocates).
+ `PortBuilder` and `UserinfoBuilder` types are intermediate types to
provide convenient generics to component setters.
+ `Error` type is a builder error.
+ `Buildable` trait indicates the syntax corresponding to the string types
(such as `IriStr` or `UriReferenceStr`) can be constructed by the builder.

### Fixed
* Fix normalization bug.
+ Previously, trailing colon of an authority (with empty port) was not
stripped. Now this is fixed.

### Changed (non-breaking)
* Deprecate `percent_encoding` module in favor of the new name `percent_encode`.
+ Previously exported items are still provided from `percent_encoding`
module to keep backward compatibility.

## [0.5.5]

* Add `RiQueryStr` and `RiQueryString` types for query.
Expand Down Expand Up @@ -583,8 +616,9 @@ Beleive rustdoc rather than this CHANGELOG.**

Totally rewritten.

[Unreleased]: <https://github.com/lo48576/iri-string/compare/v0.5.5...develop>
[0.5.4]: <https://github.com/lo48576/iri-string/releases/tag/v0.5.5>
[Unreleased]: <https://github.com/lo48576/iri-string/compare/v0.5.6...develop>
[0.5.6]: <https://github.com/lo48576/iri-string/releases/tag/v0.5.6>
[0.5.5]: <https://github.com/lo48576/iri-string/releases/tag/v0.5.5>
[0.5.4]: <https://github.com/lo48576/iri-string/releases/tag/v0.5.4>
[0.5.3]: <https://github.com/lo48576/iri-string/releases/tag/v0.5.3>
[0.5.2]: <https://github.com/lo48576/iri-string/releases/tag/v0.5.2>
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iri-string"
version = "0.5.5"
version = "0.5.6"
authors = ["YOSHIOKA Takuma <nop_thread@nops.red>"]
edition = "2021"
rust-version = "1.58"
Expand Down
55 changes: 55 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod error;

use core::cmp::Ordering;
use core::fmt;

#[cfg(feature = "alloc")]
use alloc::string::String;
Expand All @@ -17,6 +18,17 @@ pub(crate) trait Buffer<'a> {
/// Error on extending buffer.
type ExtendError;

/// Writes the formatted input to the buffer.
///
/// Intended to be used with `std::write!`.
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<(), Self::ExtendError> {
let mut buf = FmtWritableBuffer::new(self);
match fmt::write(&mut buf, args) {
Ok(_) => Ok(()),
Err(_) => Err(buf.take_error_unwrap()),
}
}

/// Returns the content in a byte slice.
#[must_use]
fn as_bytes(&self) -> &[u8];
Expand Down Expand Up @@ -220,3 +232,46 @@ impl<'a> Buffer<'a> for ByteSliceBuf<'a> {
}
}
}

/// A wrapper type to make the buffer type writable by `core::fmt::Write`.
pub(crate) struct FmtWritableBuffer<'a, 'b, T: ?Sized + Buffer<'b>> {
/// Buffer.
buffer: &'a mut T,
/// Error.
error: Option<T::ExtendError>,
}

impl<'a, 'b, T: ?Sized + Buffer<'b>> FmtWritableBuffer<'a, 'b, T> {
/// Creates a new wrapper object.
#[inline]
#[must_use]
pub(crate) fn new(buffer: &'a mut T) -> Self {
Self {
buffer,
error: None,
}
}

/// Takes the error object out of `self` and returns it.
///
/// # Panics
///
/// Panics if the error is not set or already cleared.
#[inline]
#[must_use]
pub(crate) fn take_error_unwrap(&mut self) -> T::ExtendError {
self.error
.take()
.expect("[precondition] buffer error should be set")
}
}

impl<'a, 'b, T: ?Sized + Buffer<'b>> fmt::Write for FmtWritableBuffer<'a, 'b, T> {
fn write_str(&mut self, s: &str) -> fmt::Result {
if let Err(e) = self.buffer.push_str(s) {
self.error = Some(e);
return Err(fmt::Error);
}
Ok(())
}
}

0 comments on commit e7a93f3

Please sign in to comment.