Compare commits
No commits in common. "master" and "devel" have entirely different histories.
|
@ -1,32 +0,0 @@
|
||||||
name: Cargo Format, Check and Test
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
format:
|
|
||||||
name: cargo fmt
|
|
||||||
permissions:
|
|
||||||
# Give the default GITHUB_TOKEN write permission to commit and push the
|
|
||||||
# added or changed files to the repository.
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
|
||||||
- run: rustup component add rustfmt
|
|
||||||
- run: cargo fmt
|
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
|
||||||
with:
|
|
||||||
# Optional. Commit message for the created commit.
|
|
||||||
# Defaults to "Apply automatic changes"
|
|
||||||
commit_message: Automatical formatting
|
|
||||||
check:
|
|
||||||
name: cargo check
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
|
||||||
- run: cargo check --all-features --verbose
|
|
||||||
test:
|
|
||||||
name: cargo test
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: dtolnay/rust-toolchain@stable
|
|
||||||
- run: cargo test --all-features --verbose
|
|
|
@ -5,5 +5,7 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
// Tell Cargo that if the given file changes, to rerun this build script.
|
// Tell Cargo that if the given file changes, to rerun this build script.
|
||||||
println!("cargo:rerun-if-changed=src/hello.c");
|
println!("cargo:rerun-if-changed=src/hello.c");
|
||||||
cc::Build::new().file("lib/test.c").compile("test");
|
cc::Build::new()
|
||||||
|
.file("lib/test.c")
|
||||||
|
.compile("test");
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,18 +23,20 @@ fn main() {
|
||||||
// confirmed safe inputs
|
// confirmed safe inputs
|
||||||
let qux = unsafe { ret19() };
|
let qux = unsafe { ret19() };
|
||||||
println!("`ret19()` returned {qux}");
|
println!("`ret19()` returned {qux}");
|
||||||
let st = MyStruct { foo: 17, bar: 0x41 };
|
let st = MyStruct {
|
||||||
|
foo: 17, bar: 0x41
|
||||||
|
};
|
||||||
// converting a c "string" to a real rust String is
|
// converting a c "string" to a real rust String is
|
||||||
// a bit complicated
|
// a bit complicated
|
||||||
let info: &str = unsafe {
|
let info: &str = unsafe {
|
||||||
// convert the returned value to a rust internal CStr.
|
// convert the returned value to a rust internal CStr.
|
||||||
std::ffi::CStr::from_ptr(
|
std::ffi::CStr::from_ptr(
|
||||||
// the function returns a pointer to a array of chars on the heap
|
// the function returns a pointer to a array of chars on the heap
|
||||||
structInfo(&st),
|
structInfo(&st)
|
||||||
)
|
)
|
||||||
// now to a string slice (result)
|
// now to a string slice (result)
|
||||||
.to_str()
|
.to_str()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
println!("{info}");
|
println!("{info}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use std::any::{type_name, TypeId};
|
use std::any::{TypeId, type_name};
|
||||||
|
use std::mem::*;
|
||||||
|
use std::fmt::Debug;
|
||||||
//* # See what's behind the primitive datatypes of Rust
|
//* # See what's behind the primitive datatypes of Rust
|
||||||
//*
|
//*
|
||||||
//* This Crate shows off, how primitive Types of rust are stored in memory.
|
//* This Crate shows off, how primitive Types of rust are stored in memory.
|
||||||
|
@ -7,37 +9,23 @@ fn main() {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
items.push(true);
|
items.push(true);
|
||||||
items.push(false);
|
items.push(false);
|
||||||
investigate!(bool, items);
|
dump_type::<bool>(items);
|
||||||
|
|
||||||
let mut items = Vec::new();
|
|
||||||
items.push(String::from("foo"));
|
|
||||||
items.push(String::from("bar"));
|
|
||||||
items.push(String::from("文学"));
|
|
||||||
items.push(String::from("qux"));
|
|
||||||
investigate!(String, items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
fn dump_type<T: Debug + 'static>(items: Vec<T>) {
|
||||||
macro_rules! investigate {
|
println!("Type:\t{}", type_name::<T>());
|
||||||
($t:ty, $v:tt) => {
|
println!("\tID:\t{:?}", TypeId::of::<T>());
|
||||||
println!("Type:\t{}", type_name::<$t>());
|
println!("\tItems:");
|
||||||
println!("\tID:\t{:?}", TypeId::of::<$t>());
|
unsafe {
|
||||||
println!("\tItems:");
|
for (index, item) in items.iter().enumerate() {
|
||||||
unsafe {
|
let pointer = item as *const T;
|
||||||
for (index, item) in $v.iter().enumerate() {
|
let raw_pointer = pointer as *const u8;
|
||||||
let pointer = item as *const $t;
|
println!("\t{index:02x}\titem:\t{item:?}\n\
|
||||||
let raw_pointer: [u8; std::mem::size_of::<$t>()] =
|
\t\tpointer: {:X?}\n\
|
||||||
std::mem::transmute(item.clone());
|
\t\tmemory: {:X?}",
|
||||||
println!(
|
pointer,
|
||||||
"\t{index:02x}\titem:\t{item:?}\n\
|
*raw_pointer,
|
||||||
\t\tpointer: {:X?}\n\
|
);
|
||||||
\t\talign: {:#X} B\n\
|
|
||||||
\t\tmemory: {:X?}\n",
|
|
||||||
pointer,
|
|
||||||
std::mem::align_of::<$t>(),
|
|
||||||
raw_pointer,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
println!(
|
println!(
|
||||||
"The dark power of unsafe rust awakens!
|
"The dark power of unsafe rust awakens!
|
||||||
|
|
||||||
This is the default executable! It does not do much, use another executable.
|
This is the default executable! It does not do much, use another executable.
|
||||||
|
|
||||||
|
@ -9,6 +9,5 @@ Select your target like this:
|
||||||
|
|
||||||
To see a list of all runnable binaries, you can use the following command.
|
To see a list of all runnable binaries, you can use the following command.
|
||||||
`cargo run --bin`
|
`cargo run --bin`
|
||||||
"
|
");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue