MCPcopy Create free account
hub / github.com/awslabs/llrt / to_string

Function to_string

modules/llrt_buffer/src/buffer.rs:400–424  ·  view source on GitHub ↗
(
    this: This<Object<'_>>,
    ctx: Ctx,
    encoding: Opt<String>,
    start: Opt<i32>,
    end: Opt<i32>,
)

Source from the content-addressed store, hash-verified

398}
399
400fn to_string(
401 this: This<Object<'_>>,
402 ctx: Ctx,
403 encoding: Opt<String>,
404 start: Opt<i32>,
405 end: Opt<i32>,
406) -> Result<String> {
407 let typed_array = TypedArray::<u8>::from_object(this.0)?;
408 let bytes: &[u8] = typed_array.as_ref();
409
410 let start = start
411 .0
412 .map(|s| s.max(0) as usize)
413 .unwrap_or(0)
414 .min(bytes.len());
415 let end = end
416 .0
417 .map(|e| e.max(0) as usize)
418 .unwrap_or(bytes.len())
419 .min(bytes.len());
420 let bytes = &bytes[start..end];
421
422 let encoder = Encoder::from_optional_str(encoding.as_deref()).or_throw(&ctx)?;
423 encoder.encode_to_string(bytes, true).or_throw(&ctx)
424}
425
426fn write<'js>(
427 this: This<Object<'js>>,

Callers

nothing calls this directly

Calls 3

or_throwMethod · 0.80
encode_to_stringMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected