GithubHelp home page GithubHelp logo

restruct's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bernii

restruct's Issues

Use of undeclared crate or module `restruct`

Hello,

the example code fails with the error message:

$ cargo +nightly run                            
   Compiling test_restruct v0.1.0 (XXX)
error[E0433]: failed to resolve: use of undeclared crate or module `restruct`
 --> src/main.rs:8:14
  |
8 |     #[derive(restruct_derive::Struct)]
  |              ^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `restruct`
  |
  = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

warning: unused import: `restruct_derive::Struct`
 --> src/main.rs:1:5
  |
1 | use restruct_derive::Struct;
  |     ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0433`.
error: could not compile `test_restruct`

To learn more, run the command again with --verbose.
use restruct_derive::Struct;

fn main() {
    #![feature(const_fn)]
    #![feature(const_transmute)]

    // Generate a parser in little-endian for two 32bit integers, a float and a bool.
    #[derive(restruct_derive::Struct)]
    #[fmt="<2if?"]
    struct FooParser;

    // Pack a tuple of two integers, a float an a bool into a [u8; _]-buffer.
    let packed = FooParser::pack((1, 2, 3.0, false));
    assert_eq!(packed.len(), FooParser::SIZE);

    // Packing and unpacking can't fail at runtime.
    let unpacked = FooParser::unpack(packed);
    assert_eq!(unpacked, (1, 2, 3.0, false));
}

I'm sorry if this just a user error :/

Remove nightly features

Hello,

very cool project!

Does this project need the nightly features? I would be humbled if you could find a way to disable the use of nightly features. Otherwise it is not possible to use the project on the stable channel.

I can also help :)

Best greetings
Julian

Update the crate @ crates.io

Hey!

I noticed that the crate published at crates.io is a bit outdated - it's using deprecated rustdoc macros which have been already removed in the repo. Would you mind publishing a new crate so that users of the lib can use the crate as a dependency (rather than github repo)? Thanks :)

'Expected `()`, found `u8`'

Hi,

I'll publish a minimal example later tomorrow - its late here, but I'm trying to pack a single u8 variable, which probably is unusual - I'm just implementing the protocol I've been given.

Rust seems to think the ::pack(T) function is expecting an empty value (or a tuple..?). But when I do ::pack((val)), that makes no difference.

Apologies if this is a silly question though - any ideas?

Thanks.

Test and verify alignment-computation

We compute alignment via std::mem::align_of. While this seems to work, the approach is completely naive and almost certainly wrong.

Identify cases where this breaks so we can at least document them. Provide tests that prove edge cases in either the positive or the negative.

Future-proof conversion via repr(C)-struct-tuple

We currently go from a [u8; _] directly to a normal (...)-tuple and back. This works as long as their sizes match exactly (transmute will compile-error otherwise) but still leaves room open for error: A future compiler might decide to re-order the memory representation of a tuple-type (e.g. in order to avoid excessive alignment). The result will be safe behavior but completely garbage outcome.

The pack()- and unpack()-function should indirect via a repr(C) struct when going from/to a [u8;_] and convert that value again. This should always work and, in case the types actually match up exactly, compile to nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.