https://github.com/para-diso/magical-global
Magical Data Sharing for Rust
https://github.com/para-diso/magical-global
global-variables rust
Last synced: 2 months ago
JSON representation
Magical Data Sharing for Rust
- Host: GitHub
- URL: https://github.com/para-diso/magical-global
- Owner: PARA-DISO
- License: mit
- Created: 2024-07-20T07:57:30.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-21T07:21:30.000Z (11 months ago)
- Last Synced: 2025-02-10T02:17:58.079Z (4 months ago)
- Topics: global-variables, rust
- Language: Rust
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# magical-global
>[!TIP]
> It is a shortcut when sharing variables like C code with ease,
> and is not a good technique from the Rust perspective.Magical Data Sharing for Rust
## Usage
```rs
use magical_global as magical;fn main() {
let data:usize = 0;
// Set data to magical global
if magical::set_at(Box::new(data), 0).is_err() {
println!("failed to set data");
return;
};
// read global
let shared_data = magical::get_mut_at::(0).unwrap();
// take ownership of data
let data = magical::take_at::(0).unwrap();
}
```Read the example code to learn more.
## Limitations
* The possible areas where data can be placed are from 0 to 31.
* This crate has no memory management features.
- Recommend using the `take_at` function to free memory with the rust function.## Examples
Example code can be executed with `cargo run --example sharing` or `cargo run --example locking`
`sharing` is a simple data share, and `locking` is an Example of Mutex Lock code.