rsmemgen

Crates.iorsmemgen
lib.rsrsmemgen
version0.1.0
created_at2025-06-18 03:24:46.878338+00
updated_at2025-06-18 03:24:46.878338+00
descriptionRust Memory Leak check library code generation for inline or inline(never)
homepage
repositoryhttps://github.com/jeppeter/rsmemchk
max_upload_size
id1716497
size32,052
jeppeter (jeppeter)

documentation

README

rsmemgen

rust memory leak check code generation library

Release History

  • Jun 18th 2025 to release 0.1.0 for first version

Cargo.toml

[package]
name = "cases"
version = "0.1.0"
edition = "2021"

[dependencies]
rsmemgen = "0.1.0"

[features]
rsmemchk_mode = []
debug_mode = []

build.rs


use std::error::Error;



fn main() -> Result<(),Box<dyn Error>> {
	match std::env::var("CARGO_CFG_FEATURE") {
		Ok(v) => {
			let carrs :Vec<&str> = v.split(",").collect();
			let mut idx :usize = 0;
			while idx < carrs.len() {
				if carrs[idx] == "rsmemchk_mode" {
					/*to set for RSMEMCHK_MODE for it will set environment build*/
					println!("cargo::rustc-env=RSMEMCHK_MODE=1");					
					break;
				}
				idx += 1;
			}
		},
		Err(_e) => {},
	}

	
	Ok(())
}

main.rs

use std::error::Error;
use rsmemgen::{rsmemgen_impl_inline,rsmemgen_func_inline};


struct Values {
	pub val :i32,
}

trait CallUser {
	fn call_name(&self,s :&str);
	fn call_user(&self,s :&str);
}

#[rsmemgen_impl_inline()]
impl Values {
	pub fn new(val :i32) ->  Self {
		Self {
			val :val,
		}
	}

	pub fn to_string(&self) -> String {
		println!("in line [{}:{}]",file!(),line!());
		return format!("{}",self.val);
	}
}

#[rsmemgen_impl_inline()]
impl CallUser for Values {
	fn call_name(&self,s :&str) {
		println!("value {} name {}", self.val,s);
	}
	fn call_user(&self,s :&str) {
		println!("value {} user {}", self.val,s);
	}
}

#[rsmemgen_func_inline()]
fn call_hello(s :&str) {
	println!("hello {}", s);
}

fn main() -> Result<(),Box<dyn Error>> {
    let c = Values::new(32);
    println!("{}", c.to_string());
    c.call_user("user");
    c.call_name("user");
    call_hello("newguest");
    Ok(())
}

call in cargo

cargo build --release

result call_hello or Values::call_name Values::call_user will compiled into inline

call in cargo

cargo build --release --features rsmemchk_mode

result call_hello or Values::call_name Values::call_user will compiled not inlined it will help you when used rsmemchk functions

Commit count: 68

cargo fmt