MCPcopy Create free account
hub / github.com/apache/fory / with_read_context

Method with_read_context

rust/fory-core/src/fory.rs:1065–1086  ·  view source on GitHub ↗
(
        &self,
        f: impl FnOnce(&mut ReadContext) -> Result<R, Error>,
    )

Source from the content-addressed store, hash-verified

1063 /// Uses fast path caching for O(1) access when using the same Fory instance repeatedly.
1064 #[inline(always)]
1065 fn with_read_context<R>(
1066 &self,
1067 f: impl FnOnce(&mut ReadContext) -> Result<R, Error>,
1068 ) -> Result<R, Error> {
1069 // SAFETY: Thread-local storage is only accessed from the current thread.
1070 // We use UnsafeCell to avoid RefCell's runtime borrow checking overhead.
1071 // The closure `f` does not recursively call with_read_context, so there's no aliasing.
1072 READ_CONTEXTS.with(|cache| {
1073 let cache = unsafe { &mut *cache.get() };
1074 let id = self.id;
1075
1076 let context = cache.get_or_insert_result(id, || {
1077 // Only fetch type resolver when creating a new context
1078 let type_resolver = self.get_final_type_resolver()?;
1079 Ok(Box::new(ReadContext::new(
1080 type_resolver.clone(),
1081 self.config.clone(),
1082 )))
1083 })?;
1084 f(context)
1085 })
1086 }
1087
1088 #[inline(always)]
1089 fn deserialize_with_context<T: Serializer + ForyDefault>(

Callers 2

deserializeMethod · 0.80
deserialize_fromMethod · 0.80

Calls 4

get_or_insert_resultMethod · 0.80
getMethod · 0.65
cloneMethod · 0.45

Tested by

no test coverage detected