Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
djkoloski committed Feb 3, 2021
1 parent 7ab58fa commit 05b1a19
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 4 deletions.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2021 David Koloski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ptr_meta   [![Latest Version]][crates.io] [![License]][license path] [![requires: rustc 1.47+]][Rust 1.47]

[Latest Version]: https://img.shields.io/crates/v/ptr_meta.svg
[crates.io]: https://crates.io/crates/ptr_meta
[License]: https://img.shields.io/badge/license-MIT-blue.svg
[license path]: https://github.com/djkoloski/ptr_meta/blob/master/LICENSE
[requires: rustc 1.47+]: https://img.shields.io/badge/rustc-1.47+-lightgray.svg
[Rust 1.47]: https://blog.rust-lang.org/2020/10/08/Rust-1.47.html

# ptr_meta

A radioactive stabilization of the [`ptr_meta` RFC][rfc].

[rfc]: https://rust-lang.github.io/rfcs/2580-ptr-meta.html

## Usage

### Sized types

Sized types already have `Pointee` implemented for them, so most of the time you won't have to worry
about them. However, trying to derive `Pointee` for a struct that may or may not have a DST as its
last field will cause an implementation conflict with the automatic sized implementation.

### `slice`s and `str`s

These core types have implementations built in.

### Structs with a DST as its last field

You can derive `Pointee` for last-field DSTs:

```rust
use ptr_meta::Pointee;

#[derive(Pointee)]
struct Block<H, T> {
header: H,
elements: [T],
}
```

### Trait objects

You can generate a `Pointee` for trait objects:

```rust
use ptr_meta::pointee;

// Generates Pointee for dyn Stringy
#[pointee]
trait Stringy {
fn as_string(&self) -> String;
}
```
7 changes: 7 additions & 0 deletions ptr_meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name = "ptr_meta"
version = "0.1.0"
authors = ["David Koloski <[email protected]>"]
edition = "2018"
description = "A radioactive stabilization of the ptr_meta rfc"
license = "MIT"
documentation = "https://docs.rs/ptr_meta"
repository = "https://github.com/djkoloski/ptr_meta"
keywords = ["ptr", "meta", "no_std"]
categories = ["no-std"]
readme = "crates-io.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
54 changes: 54 additions & 0 deletions ptr_meta/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ptr_meta &emsp; [![Latest Version]][crates.io] [![License]][license path] [![requires: rustc 1.47+]][Rust 1.47]

[Latest Version]: https://img.shields.io/crates/v/ptr_meta.svg
[crates.io]: https://crates.io/crates/ptr_meta
[License]: https://img.shields.io/badge/license-MIT-blue.svg
[license path]: https://github.com/djkoloski/ptr_meta/blob/master/LICENSE
[requires: rustc 1.47+]: https://img.shields.io/badge/rustc-1.47+-lightgray.svg
[Rust 1.47]: https://blog.rust-lang.org/2020/10/08/Rust-1.47.html

# ptr_meta

A radioactive stabilization of the [`ptr_meta` RFC][rfc].

[rfc]: https://rust-lang.github.io/rfcs/2580-ptr-meta.html

## Usage

### Sized types

Sized types already have `Pointee` implemented for them, so most of the time you won't have to worry
about them. However, trying to derive `Pointee` for a struct that may or may not have a DST as its
last field will cause an implementation conflict with the automatic sized implementation.

### `slice`s and `str`s

These core types have implementations built in.

### Structs with a DST as its last field

You can derive `Pointee` for last-field DSTs:

```rust
use ptr_meta::Pointee;

#[derive(Pointee)]
struct Block<H, T> {
header: H,
elements: [T],
}
```

### Trait objects

You can generate a `Pointee` for trait objects:

```rust
use ptr_meta::pointee;

// Generates Pointee for dyn Stringy
#[pointee]
trait Stringy {
fn as_string(&self) -> String;
}
```
45 changes: 45 additions & 0 deletions ptr_meta/crates-io.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ptr_meta

A radioactive stabilization of the [`ptr_meta` RFC][rfc].

[rfc]: https://rust-lang.github.io/rfcs/2580-ptr-meta.html

## Usage

### Sized types

Sized types already have `Pointee` implemented for them, so most of the time you won't have to worry
about them. However, trying to derive `Pointee` for a struct that may or may not have a DST as its
last field will cause an implementation conflict with the automatic sized implementation.

### `slice`s and `str`s

These core types have implementations built in.

### Structs with a DST as its last field

You can derive `Pointee` for last-field DSTs:

```rust
use ptr_meta::Pointee;

#[derive(Pointee)]
struct Block<H, T> {
header: H,
elements: [T],
}
```

### Trait objects

You can generate a `Pointee` for trait objects:

```rust
use ptr_meta::pointee;

// Generates Pointee for dyn Stringy
#[pointee]
trait Stringy {
fn as_string(&self) -> String;
}
```
57 changes: 54 additions & 3 deletions ptr_meta/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
//! A radioactive stabilization of the [`ptr_meta` RFC][rfc].
//!
//! [rfc]: https://rust-lang.github.io/rfcs/2580-ptr-meta.html
//!
//! ## Usage
//!
//! ### Sized types
//!
//! Sized types already have `Pointee` implemented for them, so most of the time you won't have to worry
//! about them. However, trying to derive `Pointee` for a struct that may or may not have a DST as its
//! last field will cause an implementation conflict with the automatic sized implementation.
//!
//! ### `slice`s and `str`s
//!
//! These core types have implementations built in.
//!
//! ### Structs with a DST as its last field
//!
//! You can derive `Pointee` for last-field DSTs:
//!
//! ```
//! use ptr_meta::Pointee;
//!
//! #[derive(Pointee)]
//! struct Block<H, T> {
//! header: H,
//! elements: [T],
//! }
//! ```
//!
//! ### Trait objects
//!
//! You can generate a `Pointee` for trait objects:
//!
//! ```
//! use ptr_meta::pointee;
//!
//! // Generates Pointee for dyn Stringy
//! #[pointee]
//! trait Stringy {
//! fn as_string(&self) -> String;
//! }
//! ```
#![no_std]

mod impls;

Expand All @@ -13,7 +55,7 @@ use core::{
ptr,
};

pub use ptr_meta_derive::{ptr_meta, Pointee};
pub use ptr_meta_derive::{pointee, Pointee};

/// Provides the pointer metadata type of any pointed-to type.
///
Expand Down Expand Up @@ -279,7 +321,7 @@ impl<Dyn: ?Sized> hash::Hash for DynMetadata<Dyn> {
#[cfg(test)]
mod tests {
use crate as ptr_meta;
use super::{from_raw_parts, ptr_meta, Pointee, PtrExt};
use super::{from_raw_parts, pointee, Pointee, PtrExt};

fn test_pointee<T: Pointee + ?Sized>(value: &T) {
let ptr = value as *const T;
Expand Down Expand Up @@ -325,7 +367,7 @@ mod tests {

#[test]
fn trait_objects() {
#[ptr_meta]
#[pointee]
trait TestTrait {
fn foo(&self);
}
Expand Down Expand Up @@ -376,5 +418,14 @@ mod tests {
struct TestDyn {
tail: dyn core::any::Any,
}

#[pointee]
trait TestTrait {}

#[allow(dead_code)]
#[derive(Pointee)]
struct TestCustomDyn {
tail: dyn TestTrait,
}
}
}
2 changes: 1 addition & 1 deletion ptr_meta_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn derive_pointee_impl(input: &DeriveInput) -> TokenStream {

/// Generates an implementation of `Pointee` for trait objects.
#[proc_macro_attribute]
pub fn ptr_meta(
pub fn pointee(
_attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
Expand Down

0 comments on commit 05b1a19

Please sign in to comment.