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() {
|
||||
// Tell Cargo that if the given file changes, to rerun this build script.
|
||||
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
|
||||
let qux = unsafe { ret19() };
|
||||
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
|
||||
// a bit complicated
|
||||
let info: &str = unsafe {
|
||||
// convert the returned value to a rust internal CStr.
|
||||
std::ffi::CStr::from_ptr(
|
||||
// the function returns a pointer to a array of chars on the heap
|
||||
structInfo(&st),
|
||||
structInfo(&st)
|
||||
)
|
||||
// now to a string slice (result)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
// now to a string slice (result)
|
||||
.to_str()
|
||||
.unwrap()
|
||||
};
|
||||
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
|
||||
//*
|
||||
//* This Crate shows off, how primitive Types of rust are stored in memory.
|
||||
|
@ -7,37 +9,23 @@ fn main() {
|
|||
let mut items = Vec::new();
|
||||
items.push(true);
|
||||
items.push(false);
|
||||
investigate!(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);
|
||||
dump_type::<bool>(items);
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! investigate {
|
||||
($t:ty, $v:tt) => {
|
||||
println!("Type:\t{}", type_name::<$t>());
|
||||
println!("\tID:\t{:?}", TypeId::of::<$t>());
|
||||
println!("\tItems:");
|
||||
unsafe {
|
||||
for (index, item) in $v.iter().enumerate() {
|
||||
let pointer = item as *const $t;
|
||||
let raw_pointer: [u8; std::mem::size_of::<$t>()] =
|
||||
std::mem::transmute(item.clone());
|
||||
println!(
|
||||
"\t{index:02x}\titem:\t{item:?}\n\
|
||||
\t\tpointer: {:X?}\n\
|
||||
\t\talign: {:#X} B\n\
|
||||
\t\tmemory: {:X?}\n",
|
||||
pointer,
|
||||
std::mem::align_of::<$t>(),
|
||||
raw_pointer,
|
||||
);
|
||||
}
|
||||
fn dump_type<T: Debug + 'static>(items: Vec<T>) {
|
||||
println!("Type:\t{}", type_name::<T>());
|
||||
println!("\tID:\t{:?}", TypeId::of::<T>());
|
||||
println!("\tItems:");
|
||||
unsafe {
|
||||
for (index, item) in items.iter().enumerate() {
|
||||
let pointer = item as *const T;
|
||||
let raw_pointer = pointer as *const u8;
|
||||
println!("\t{index:02x}\titem:\t{item:?}\n\
|
||||
\t\tpointer: {:X?}\n\
|
||||
\t\tmemory: {:X?}",
|
||||
pointer,
|
||||
*raw_pointer,
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
fn main() {
|
||||
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.
|
||||
|
||||
|
@ -9,6 +9,5 @@ Select your target like this:
|
|||
|
||||
To see a list of all runnable binaries, you can use the following command.
|
||||
`cargo run --bin`
|
||||
"
|
||||
);
|
||||
");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue