Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<br>

- Offers safe, direct Rust wrappers for the entire MuJoCo API.
- Offers safe, low-level Rust wrappers for the entire MuJoCo API.
- Provides getters for all struct fields and setters for user-modifiable fields,
instead of allowing direct field access.
- Implements automatic resource management via Rust's RAII pattern.
Expand Down
4 changes: 2 additions & 2 deletions src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub(crate) fn array_flatslice<T, const M: usize, const N: usize>(

pub(crate) fn copy_str_to_c_chararray<const N: usize>(
s: &str,
c_array: &mut [i8; N],
c_array: &mut [std::ffi::c_char; N],
) {
let c_str = std::ffi::CString::new(s).expect("string must not contain internal null bytes");
let bytes = c_str.into_bytes_with_nul();
assert!(bytes.len() <= N, "string must be less than {N} bytes long");
bytes.iter().enumerate().for_each(|(i, &b)| {c_array[i] = b as i8});
bytes.iter().enumerate().for_each(|(i, &b)| {c_array[i] = b as std::ffi::c_char});
c_array[bytes.len()..].fill(0); // fill the rest with zeros
}

Expand Down
4 changes: 2 additions & 2 deletions src/types/visualization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ macro_rules! chars {
let bytes = $name.as_bytes();
let (len, limit) = (bytes.len(), self.$name.len() - 1);
assert!(len <= limit, "{}: `{len}` is too long, max {limit} bytes", stringify!($name));
bytes.iter().enumerate().for_each(|(i, &b)| self.$name[i] = b as i8);
bytes.iter().enumerate().for_each(|(i, &b)| self.$name[i] = b as std::ffi::c_char);
self.$name[bytes.len()] = 0; // null-terminate
self
}
Expand All @@ -481,7 +481,7 @@ impl mjvFigure {
assert!(index < mjMAXLINE, "`set_linename`: too large index `{index}`, must be index < {mjMAXLINE}");
let (len, limit) = (name.as_bytes().len(), self.linename[index].len() - 1);
assert!(len <= limit, "Line name `{name}` is too long, max {limit} bytes");
name.as_bytes().iter().enumerate().for_each(|(i, &b)| self.linename[index][i] = b as i8);
name.as_bytes().iter().enumerate().for_each(|(i, &b)| self.linename[index][i] = b as std::ffi::c_char);
self.linename[index][len] = 0; // null-terminate
self
}
Expand Down