-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test
Box
derive for sized and unsized types
- Loading branch information
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use blanket::blanket; | ||
use impls::impls; | ||
|
||
#[blanket(derive(Box))] | ||
pub trait StringLike { | ||
fn into_utf8(self) -> Vec<u8>; | ||
} | ||
|
||
impl StringLike for str { | ||
fn into_utf8(self) -> Vec<u8> { | ||
self.as_bytes().into() | ||
} | ||
} | ||
|
||
fn main() { | ||
assert!(impls!(str: StringLike)); | ||
assert!(impls!(Box<str>: StringLike)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> tests/derive_box/fails/unsized_type_self_receiver.rs:10:18 | ||
| | ||
10 | fn into_utf8(self) -> Vec<u8> { | ||
| ^^^^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `str` | ||
= help: unsized fn params are gated as an unstable feature | ||
help: function arguments must have a statically known size, borrowed types always have a known size | ||
| | ||
10 | fn into_utf8(&self) -> Vec<u8> { | ||
| + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use blanket::blanket; | ||
use impls::impls; | ||
|
||
#[blanket(derive(Box))] | ||
pub trait StringLike { | ||
fn is_utf8(&self) -> bool; | ||
} | ||
|
||
impl StringLike for str { | ||
fn is_utf8(&self) -> bool { | ||
true | ||
} | ||
} | ||
|
||
fn main() { | ||
assert!(impls!(str: StringLike)); | ||
assert!(impls!(Box<str>: StringLike)); | ||
} |