MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / get_write_parameters

Function get_write_parameters

modules/llrt_buffer/src/buffer.rs:431–459  ·  view source on GitHub ↗
(args: &Rest<Value<'_>>, len: usize)

Source from the content-addressed store, hash-verified

429}
430
431fn get_write_parameters(args: &Rest<Value<'_>>, len: usize) -> Result<(usize, usize, String)> {
432 let mut offset = 0;
433 let mut length = len;
434 let mut encoding = "utf8".to_owned();
435
436 if let Some(v1) = args.0.first() {
437 if let Some(s) = v1.as_string() {
438 return Ok((0, len, s.to_string()?));
439 }
440 offset = v1.as_int().unwrap_or(0) as usize;
441 }
442
443 if let Some(v2) = args.0.get(1) {
444 if let Some(s) = v2.as_string() {
445 return Ok((offset, len - offset, s.to_string()?));
446 }
447 length = v2
448 .as_int()
449 .map_or(len - offset, |l| (l as usize).min(len - offset));
450 }
451
452 if let Some(v3) = args.0.get(2) {
453 if let Some(s) = v3.as_string() {
454 encoding = s.to_string()?;
455 }
456 }
457
458 Ok((offset, length, encoding))
459}
460
461fn safe_byte_slice(s: &str, end: usize) -> (&[u8], usize) {
462 let bytes = s.as_bytes();

Callers 1

writeFunction · 0.85

Calls 3

firstMethod · 0.80
to_stringMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected