Skip to main content

yttrium_std_attach/
lib.rs

1#![allow(clippy::needless_return)]
2#![deny(clippy::implicit_return)]
3use yttrium_key_base as key_base;
4#[cfg(feature = "loader")]
5#[no_mangle]
6pub fn key_create() -> *mut dyn key_base::Key {
7	return Box::into_raw(Box::new(std_attach {
8		info: create_key_info(),
9		function: key_function,
10	}));
11}
12
13pub fn safe_create() -> Box<dyn key_base::Key> {
14	return Box::new(std_attach {
15		info: create_key_info(),
16		function: key_function,
17	});
18}
19
20fn create_key_info() -> key_base::KeyInfo {
21	return key_base::KeyInfo {
22		name: String::from("attach"),
23		parameters_required: vec![1],
24	};
25}
26#[allow(non_camel_case_types)]
27struct std_attach {
28	pub info: key_base::KeyInfo,
29	pub function: fn(parameter: &[String], environment: &mut key_base::environment::Environment) -> Result<String, String>,
30}
31
32impl key_base::Key for std_attach {
33	fn get_key_info(&self) -> &key_base::KeyInfo {
34		return &self.info;
35	}
36
37	fn get_key_function(&self) -> fn(parameter: &[String], environment: &mut key_base::environment::Environment) -> Result<String, String> {
38		return self.function;
39	}
40}
41
42fn key_function(parameter: &[String], environment: &mut key_base::environment::Environment) -> Result<String, String> {
43	environment.attachments.push(parameter[0].clone());
44	return Ok(String::new());
45}