Coder Social home page Coder Social logo

state's People

Contributors

sergiobenitez avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

state's Issues

"Unstable library feature" Error while compiling

Hey!

Thanks for all the work with rocket, and all related libraries.

Since an update on Rocket, i can't seem to get state to compile. I've narrowed it down to state's 7576652 commit. (To which rocket updated on commit SergioBenitez/Rocket@63a1452).

Here's how the error looks like:

error[E0658]: use of unstable library feature 'unsafe_cell_get_mut'
  --> /home/misterio/.cargo/git/checkouts/state-461be979d187f8b7/504ef71/src/shim.rs:41:40
   |
41 |             #[cfg(not(loom))] { self.0.get_mut() }
   |                                        ^^^^^^^
   |
   = note: see issue #76943 <https://github.com/rust-lang/rust/issues/76943> for more information

error: aborting due to previous error

If i understand correctly, this seems to require users to use unstable features? Can i somehow get it to work without nightly builds?

Thanks a lot!

Sample error

Hi, I'm trying to follow the example code here https://docs.rs/state/0.4.1/state/

The compiler complains

error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
 --> src/main.rs:7:49
  |
7 | static CONFIG: Storage<RwLock<Configuration>> = Storage::new();
  |                                                 ^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted

Code:

use state::Storage;
use std::sync::RwLock;

struct Configuration {}

static CONFIG: Storage<RwLock<Configuration>> = Storage::new();

fn main() {
    let config = Configuration {
        /* fill in structure at run-time from user input */
    };

    // Make the config avaiable globally.
    CONFIG.set(RwLock::new(config));

    /* at any point later in the program, in any thread */
    let mut_config = CONFIG.get().write();
}

What am I missing?

no `LocalStorage` in the root

error[E0432]: unresolved import `state::LocalStorage`
 --> src/lib.rs:1:5
  |
1 | use state::LocalStorage;
  |     ^^^^^^^^^^^^^^^^^^^ no `LocalStorage` in the root

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.

If I do use state::Storage;, it imports fine... 0.4.2 in Cargo.toml... what could it be?

Thread local state in Container without Send

It would be ideal to be able to have non-Send types in thread local storage in a container. As long as they stay on the thread, that should work, right?

An alternate solution would be to create a separate thread local version of Container.

Thunk Example

In the docs you mention that we can use State to create thunks. Is there any example of this somewhere?

Container Iterator

There is no way to list all values from Container.
Getting an iterator is probably not very useful since values have distinct types. What I really need is to have a way to debug-print the Container.

calls in statics are limited to constant functions, tuple structs and tuple variants

Hi, I'm trying to follow the example code here https://docs.rs/state/0.4.1/state/

The compiler complains

error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
 --> src/main.rs:7:49
  |
7 | static CONFIG: Storage<RwLock<Configuration>> = Storage::new();
  |                                                 ^^^^^^^^^^^^^^
error: aborting due to previous error; 1 warning emitted

Code:

use state::Storage;
use std::sync::RwLock;

struct Configuration {}

static CONFIG: Storage<RwLock<Configuration>> = Storage::new();

fn main() {
    let config = Configuration {
        /* fill in structure at run-time from user input */
    };

    // Make the config avaiable globally.
    CONFIG.set(RwLock::new(config));

    /* at any point later in the program, in any thread */
    let mut_config = CONFIG.get().write();
}

What am I missing?

Thread-local Container

Objects are required to be Send + Sync because the container is expected to be used from multiple threads. To have mutability, it is necessary to wrap everything with Mutex. Having a single-threaded variant would simplify this process.

Compile error after update state v0.3.1 -> v0.3.2

cargo update
    Updating registry `https://github.com/rust-lang/crates.io-index`
    Updating futures v0.1.15 -> v0.1.16
    Updating futures-cpupool v0.1.5 -> v0.1.6
    Updating gcc v0.3.53 -> v0.3.54
    Updating itoa v0.3.3 -> v0.3.4
    Updating ordermap v0.2.11 -> v0.2.12
    Updating state v0.3.1 -> v0.3.2
    Updating yansi v0.3.3 -> v0.3.4
cargo build --all
 Downloading itoa v0.3.4
 Downloading gcc v0.3.54
 Downloading futures v0.1.16
 Downloading futures-cpupool v0.1.6
 Downloading yansi v0.3.4
 Downloading ordermap v0.2.12
 Downloading state v0.3.2
   Compiling ordermap v0.2.12
   Compiling itoa v0.3.4
   Compiling gcc v0.3.54
   Compiling state v0.3.2
   Compiling yansi v0.3.4
   Compiling futures v0.1.16
error[E0493]: destructors in constant functions are an unstable feature
  --> C:\Users\fluxx\.cargo\registry\src\github.com-1ecc6299db9ec823\state-0.3.2\src\container.rs:95:9
   |
95 | /         Container {
96 | |             init: Init::new(),
97 | |             map: UnsafeCell::new(0 as *mut _),
98 | |             mutex: AtomicUsize::new(0)
99 | |         }
   | |_________^
   |
   = help: in Nightly builds, add `#![feature(drop_types_in_const)]` to the crate attributes to enable

error[E0493]: destructors in constant functions are an unstable feature
  --> C:\Users\fluxx\.cargo\registry\src\github.com-1ecc6299db9ec823\state-0.3.2\src\storage.rs:70:9
   |
70 | /         Storage {
71 | |             _phantom: PhantomData,
72 | |             item: UnsafeCell::new(0 as *mut T),
73 | |             init: Init::new()
74 | |         }
   | |_________^
   |
   = help: in Nightly builds, add `#![feature(drop_types_in_const)]` to the crate attributes to enable

error: aborting due to 2 previous errors

error: Could not compile `state`.

Update loom dependency to 0.5

> cargo audit
    Fetching advisory database from `https://github.com/RustSec/advisory-db.git`
      Loaded 305 security advisories (from /Users/ryadom/.cargo/advisory-db)
    Updating crates.io index
    Scanning Cargo.lock for vulnerabilities (233 crate dependencies)
Crate:         generator
Version:       0.6.25
Title:         Generators can cause data races if non-Send types are used in their generator functions
Date:          2020-11-16
ID:            RUSTSEC-2020-0151
URL:           https://rustsec.org/advisories/RUSTSEC-2020-0151
Solution:      Upgrade to >=0.7.0
Dependency tree:
generator 0.6.25
└── loom 0.3.6
    └── state 0.4.2
        ├── rocket_http 0.5.0-dev
        │   ├── rocket_codegen 0.5.0-dev
        │   └── rocket 0.5.0-dev
        └── rocket 0.5.0-dev

Examples

Hello!

I'm very interested in this crate. However, I think getting started would be much aided by a couple of minimal examples? Do this exist somewhere? If any exist maybe they could be added to the .readme?

Latest rust nightly throws error with provided example

error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants --> src/main.rs:38:38 | 38 | static GLOBAL: state::Storage<u32> = state::Storage::new();

I realize that this is likely due to a change in what are allowed to be global statics, but is there any workaround for this? I'm trying to write a server in Rust which needs to run threads at all times but they also need to referenced back to so I need some way to keep track of them. If this isn't a solution, what would you recommend? Nevermind, I found the State page of the Rocket guide which should work, but the README should still probably be updated.

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.