Download next.js/turbopack/crates/turbopack-dev-server/src/invalidation.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.17 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-dev-server/src/invalidation.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-dev-server/src/invalidation.rs
-
curl -L -o invalidation.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-dev-server/src/invalidation.rs
3.17 kB
| use std::{ | |
| any::Any, | |
| fmt::{Display, Formatter}, | |
| }; | |
| use hyper::{Method, Uri}; | |
| use turbo_tasks::{FxIndexSet, InvalidationReason, InvalidationReasonKind, util::StaticOrArc}; | |
| /// Computation was caused by a request to the server. | |
| pub struct ServerRequest { | |
| pub method: Method, | |
| pub uri: Uri, | |
| } | |
| impl InvalidationReason for ServerRequest { | |
| fn kind(&self) -> Option<StaticOrArc<dyn InvalidationReasonKind>> { | |
| Some(StaticOrArc::Static(&SERVER_REQUEST_KIND)) | |
| } | |
| } | |
| impl Display for ServerRequest { | |
| fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | |
| write!(f, "{} {}", self.method, self.uri.path()) | |
| } | |
| } | |
| /// Invalidation kind for [ServerRequest] | |
| struct ServerRequestKind; | |
| static SERVER_REQUEST_KIND: ServerRequestKind = ServerRequestKind; | |
| impl InvalidationReasonKind for ServerRequestKind { | |
| fn fmt( | |
| &self, | |
| reasons: &FxIndexSet<StaticOrArc<dyn InvalidationReason>>, | |
| f: &mut Formatter<'_>, | |
| ) -> std::fmt::Result { | |
| let example = reasons | |
| .into_iter() | |
| .map(|reason| { | |
| let reason: &dyn InvalidationReason = &**reason; | |
| (reason as &dyn Any) | |
| .downcast_ref::<ServerRequest>() | |
| .unwrap() | |
| }) | |
| .min_by_key(|reason| reason.uri.path().len()) | |
| .unwrap(); | |
| write!( | |
| f, | |
| "{} requests ({} {}, ...)", | |
| reasons.len(), | |
| example.method, | |
| example.uri.path() | |
| ) | |
| } | |
| } | |
| /// Side effect that was caused by a request to the server. | |
| pub struct ServerRequestSideEffects { | |
| pub method: Method, | |
| pub uri: Uri, | |
| } | |
| impl InvalidationReason for ServerRequestSideEffects { | |
| fn kind(&self) -> Option<StaticOrArc<dyn InvalidationReasonKind>> { | |
| Some(StaticOrArc::Static(&SERVER_REQUEST_SIDE_EFFECTS_KIND)) | |
| } | |
| } | |
| impl Display for ServerRequestSideEffects { | |
| fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | |
| write!(f, "side effects of {} {}", self.method, self.uri.path()) | |
| } | |
| } | |
| /// Invalidation kind for [ServerRequestSideEffects] | |
| struct ServerRequestSideEffectsKind; | |
| static SERVER_REQUEST_SIDE_EFFECTS_KIND: ServerRequestSideEffectsKind = | |
| ServerRequestSideEffectsKind; | |
| impl InvalidationReasonKind for ServerRequestSideEffectsKind { | |
| fn fmt( | |
| &self, | |
| reasons: &FxIndexSet<StaticOrArc<dyn InvalidationReason>>, | |
| f: &mut Formatter<'_>, | |
| ) -> std::fmt::Result { | |
| let example = reasons | |
| .into_iter() | |
| .map(|reason| { | |
| let reason: &dyn InvalidationReason = &**reason; | |
| (reason as &dyn Any) | |
| .downcast_ref::<ServerRequestSideEffects>() | |
| .unwrap() | |
| }) | |
| .min_by_key(|reason| reason.uri.path().len()) | |
| .unwrap(); | |
| write!( | |
| f, | |
| "side effects of {} requests ({} {}, ...)", | |
| reasons.len(), | |
| example.method, | |
| example.uri.path() | |
| ) | |
| } | |
| } | |