Skip to content

Commit

Permalink
0.10.0 release cleanup (#102)
Browse files Browse the repository at this point in the history
* Remove the Split trait

* Version up to 0.10.0
  • Loading branch information
maciejhirsz authored Apr 2, 2020
1 parent 0457e36 commit 1f575f3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 90 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions logos-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "logos-derive"
version = "0.10.0-rc6"
version = "0.10.0"
authors = ["Maciej Hirsz <[email protected]>"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
description = "Create ridiculously fast Lexers"
repository = "https://github.com/maciejhirsz/logos"
documentation = "https://docs.rs/logos-derive"
Expand Down
2 changes: 1 addition & 1 deletion logos-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub fn logos(input: TokenStream) -> TokenStream {
Self: ::logos::source::WithSource<Source>,
{
use ::logos::internal::LexerInternal;
use ::logos::source::{Source as Src, Split};
use ::logos::source::{Source as Src};

type Lexer<S> = ::logos::Lexer<#name, S>;

Expand Down
6 changes: 3 additions & 3 deletions logos/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "logos"
version = "0.10.0-rc6"
version = "0.10.0"
authors = ["Maciej Hirsz <[email protected]>"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
description = "Create ridiculously fast Lexers"
repository = "https://github.com/maciejhirsz/logos"
documentation = "https://docs.rs/logos"
Expand All @@ -12,7 +12,7 @@ readme = "../README.md"
edition = "2018"

[dependencies]
logos-derive = { version = "0.10.0-rc6", optional = true }
logos-derive = { version = "0.10.0", optional = true }

[features]
default = ["export_derive", "std"]
Expand Down
80 changes: 2 additions & 78 deletions logos/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,33 +219,6 @@ pub trait Chunk<'source>: Sized + Copy + PartialEq + Eq {
unsafe fn from_ptr(ptr: *const u8) -> Self;
}

/// A trait implemented for byte arrays that allow splitting them into two,
/// with the resulting sizes known at compile time.
pub trait Split<Target> {
/// Remainder after splitting. This must be statically safe so that
/// `Target` + `Remainder` = `Self`.
///
/// **Implementations must guarantee that these are not overlapping!**
type Remainder;

/// Split self into `Target` and `Remainder`.
///
/// ```rust
/// use logos::source::Split;
///
/// fn main() {
/// let bytes = b"foobar";
///
/// assert_eq!(bytes.split(), (b'f', b"oobar")); // (u8, &[u8; 5])
/// assert_eq!(bytes.split(), (b"f", b"oobar")); // (&[u8; 1], &[u8; 5])
/// assert_eq!(bytes.split(), (b"fo", b"obar")); // ...
/// assert_eq!(bytes.split(), (b"foo", b"bar"));
/// assert_eq!(bytes.split(), (b"foob", b"ar"));
/// assert_eq!(bytes.split(), (b"fooba", b"r"));
/// }
fn split(self) -> (Target, Self::Remainder);
}

impl<'source> Chunk<'source> for u8 {
const SIZE: usize = 1;

Expand All @@ -256,23 +229,7 @@ impl<'source> Chunk<'source> for u8 {
}

macro_rules! impl_array {
(@byte $size:expr, 1) => (
impl<'source> Split<u8> for &'source [u8; $size] {
type Remainder = &'source [u8; $size - 1];

#[inline]
fn split(self) -> (u8, &'source [u8; $size - 1]) {
unsafe {(
self[0],
Chunk::from_ptr((self as *const u8).add(1)),
)}
}
}
);

(@byte $size:expr, $ignore:tt) => ();

($($size:expr => ( $( $split:tt ),* ))*) => ($(
($($size:expr),*) => ($(
impl<'source> Chunk<'source> for &'source [u8; $size] {
const SIZE: usize = $size;

Expand All @@ -281,40 +238,7 @@ macro_rules! impl_array {
&*(ptr as *const [u8; $size])
}
}

$(
impl_array! { @byte $size, $split }

impl<'source> Split<&'source [u8; $split]> for &'source [u8; $size] {
type Remainder = &'source [u8; $size - $split];

#[inline]
fn split(self) -> (&'source [u8; $split], &'source [u8; $size - $split]) {
unsafe {(
Chunk::from_ptr(self as *const u8),
Chunk::from_ptr((self as *const u8).add($split)),
)}
}
}
)*
)*);
}

impl_array! {
1 => ()
2 => (1)
3 => (1, 2)
4 => (1, 2, 3)
5 => (1, 2, 3, 4)
6 => (1, 2, 3, 4, 5)
7 => (1, 2, 3, 4, 5, 6)
8 => (1, 2, 3, 4, 5, 6, 7)
9 => (1, 2, 3, 4, 5, 6, 7, 8)
10 => (1, 2, 3, 4, 5, 6, 7, 8, 9)
11 => (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
12 => (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
13 => (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)
14 => (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
15 => (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
16 => (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
}
impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "tests"
version = "0.0.0"
authors = ["Maciej Hirsz <[email protected]>"]
license = "MIT/Apache-2.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/maciejhirsz/logos"
edition = "2018"

Expand Down

0 comments on commit 1f575f3

Please sign in to comment.