-
-
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.
feat: redo initialize for impl + no_std + ci (#1)
Signed-off-by: tison <wander4096@gmail.com>
- Loading branch information
Showing
17 changed files
with
836 additions
and
207 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,19 @@ | ||
# Copyright 2024 tison <wander4096@gmail.com> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
[alias] | ||
x = "run --package x --" | ||
|
||
[env] | ||
CARGO_WORKSPACE_DIR = { value = "", relative = true } |
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,16 @@ | ||
# Copyright 2024 tison <wander4096@gmail.com> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
github: tisonkun | ||
|
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
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
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 |
---|---|---|
@@ -1,3 +1,63 @@ | ||
# Mea | ||
# Make Easy Async (Mea) | ||
|
||
Mea (Made easy async) provides async utilities that are runtime agnostic. | ||
[![Crates.io][crates-badge]][crates-url] | ||
[![Documentation][docs-badge]][docs-url] | ||
[![MSRV 1.75][msrv-badge]](https://www.whatrustisit.com) | ||
[![Apache 2.0 licensed][license-badge]][license-url] | ||
[![Build Status][actions-badge]][actions-url] | ||
|
||
[crates-badge]: https://img.shields.io/crates/v/mea.svg | ||
[crates-url]: https://crates.io/crates/mea | ||
[docs-badge]: https://docs.rs/mea/badge.svg | ||
[msrv-badge]: https://img.shields.io/badge/MSRV-1.75-green?logo=rust | ||
[docs-url]: https://docs.rs/mea | ||
[license-badge]: https://img.shields.io/crates/l/mea | ||
[license-url]: LICENSE | ||
[actions-badge]: https://github.com/tisonkun/mea/actions/workflows/ci.yml/badge.svg | ||
[actions-url]: https://github.com/tisonkun/mea/actions/workflows/ci.yml | ||
|
||
## Overview | ||
|
||
Mea provides async utilities that are runtime agnostic. | ||
|
||
* WaitGroup | ||
|
||
## Usage | ||
|
||
### Default Features | ||
|
||
Add the dependency to your `Cargo.toml` via: | ||
|
||
```toml | ||
mea = { version = "<version>" } | ||
``` | ||
|
||
### `no_std` | ||
|
||
By default, Mea enables the `std` feature and thus depends on the Rust standard library. To use Mea in a | ||
`no_std` Rust environment, disable the default features and choose one of the following runtime features. | ||
|
||
To use it on Linux, FreeBSD, Windows, and macOS, add the `sync-mutex` feature: | ||
|
||
```toml | ||
mea = { version = "<version>", default-features = false, features = ["sync-mutex"] } | ||
``` | ||
|
||
To use it in an embedded environment, use [ | ||
`critical-section`](https://github.com/rust-embedded/critical-section/) and add one of its implementation libraries by yourself: | ||
|
||
```toml | ||
mea = { version = "<version>", default-features = false, features = ["sync-critical-section"] } | ||
# choose a critical-section impl; for example, for single-core Cortex-M targets: | ||
# cortex-m = { version = "0.7.6", features = ["critical-section-single-core"]} | ||
``` | ||
|
||
## Minimum Rust version policy | ||
|
||
This crate is built against the latest stable release, and its minimum supported rustc version is 1.75.0. | ||
|
||
The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if cronexpr 1.0 requires Rust 1.20.0, then cronexpr 1.0.z for all values of z will also require Rust 1.20.0 or newer. However, cronexpr 1.y for y > 0 may require a newer minimum version of Rust. | ||
|
||
## License | ||
|
||
This project is licensed under [Apache License, Version 2.0](LICENSE). |
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,50 @@ | ||
# Copyright 2024 tison <wander4096@gmail.com> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
[package] | ||
name = "mea" | ||
version = "0.0.2" | ||
|
||
categories = ["asynchronous", "concurrency", "no-std"] | ||
description = "Async Rust utilities that are runtime agnostic." | ||
documentation = "https://docs.rs/mea" | ||
keywords = ["waitgroup", "asynchronous", "concurrency", "synchronization"] | ||
|
||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
readme.workspace = true | ||
repository.workspace = true | ||
rust-version.workspace = true | ||
|
||
[package.metadata.docs.rs] | ||
all-features = true | ||
rustdoc-args = ["--cfg", "docsrs"] | ||
|
||
[features] | ||
default = ["std"] | ||
std = [] | ||
|
||
# no_std impls for the internal sync primitives | ||
sync-critical-section = ["dep:critical-section"] | ||
sync-futex = ["dep:atomic-wait"] | ||
|
||
[dependencies] | ||
atomic-wait = { version = "1.1.0", optional = true } | ||
critical-section = { version = "1.2.0", optional = true } | ||
|
||
[dev-dependencies] | ||
critical-section = { version = "1.2.0", features = ["std"] } | ||
pollster = { version = "0.3.0" } | ||
tokio = { version = "1.41.0", features = ["full"] } |
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,39 @@ | ||
// Copyright 2024 tison <wander4096@gmail.com> | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use core::cell::RefCell; | ||
|
||
pub(crate) struct Mutex<T>(critical_section::Mutex<RefCell<T>>); | ||
|
||
impl<T> Mutex<T> { | ||
#[inline] | ||
pub(crate) const fn new(t: T) -> Self { | ||
Self(critical_section::Mutex::new(RefCell::new(t))) | ||
} | ||
|
||
pub(crate) fn with<F, R>(&self, f: F) -> R | ||
where | ||
F: FnOnce(&mut T) -> R, | ||
{ | ||
critical_section::with(|cs| { | ||
let mut this = self | ||
.0 | ||
.borrow(cs) | ||
.try_borrow_mut() | ||
// SAFETY: The outer with closure guarantees to borrow with token 'cs' exactly once. | ||
.expect("[BUG] borrow the mutex multiple times"); | ||
f(&mut this) | ||
}) | ||
} | ||
} |
Oops, something went wrong.