mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-24 06:34:09 +00:00
Upgrade dependencies and refactor serialization in build.rs
- Updated `bincode` to version 2.0.1, modifying serialization calls to use the new API with `serde` support. - Added new dependencies in `Cargo.lock`, including `alloca`, `atomic-waker`, and `aws-lc-rs`, ensuring compatibility with the latest features. - Refactored file creation and serialization logic in `build.rs` for improved clarity and performance. - Updated various dependencies in `Cargo.toml` to their latest versions, enhancing overall project stability and functionality.
This commit is contained in:
parent
0a4496a6c9
commit
71ea25fe0e
47 changed files with 933 additions and 517 deletions
|
|
@ -1,11 +1,13 @@
|
|||
use hyper::{header::CONTENT_TYPE, Body, Response, StatusCode};
|
||||
use bytes::Bytes;
|
||||
use http_body_util::Full;
|
||||
use hyper::{header::CONTENT_TYPE, Response, StatusCode};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub fn msgpack_ok<T: Serialize>(value: T) -> Response<Body> {
|
||||
pub fn msgpack_ok<T: Serialize>(value: T) -> Response<Full<Bytes>> {
|
||||
msgpack(value, StatusCode::OK)
|
||||
}
|
||||
|
||||
pub fn msgpack<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
|
||||
pub fn msgpack<T: Serialize>(value: T, code: StatusCode) -> Response<Full<Bytes>> {
|
||||
let mut serialized = Vec::new();
|
||||
let mut serializer = rmp_serde::Serializer::new(&mut serialized)
|
||||
.with_human_readable()
|
||||
|
|
@ -15,14 +17,14 @@ pub fn msgpack<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
|
|||
return Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header(CONTENT_TYPE, "text/plain")
|
||||
.body(Body::from(err.to_string()))
|
||||
.body(Full::new(Bytes::from(err.to_string())))
|
||||
.unwrap();
|
||||
};
|
||||
|
||||
Response::builder()
|
||||
.status(code)
|
||||
.header(CONTENT_TYPE, "application/msgpack")
|
||||
.body(Body::from(serialized))
|
||||
.body(Full::new(Bytes::from(serialized)))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
|
|
@ -45,14 +47,14 @@ pub fn deserialize_msgpack<'a, T: Deserialize<'a>>(
|
|||
T::deserialize(&mut deserializer)
|
||||
}
|
||||
|
||||
pub fn json<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
|
||||
pub fn json<T: Serialize>(value: T, code: StatusCode) -> Response<Full<Bytes>> {
|
||||
let serialized = match serde_json::to_string(&value) {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
return Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header(CONTENT_TYPE, "text/plain")
|
||||
.body(Body::from(err.to_string()))
|
||||
.body(Full::new(Bytes::from(err.to_string())))
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
|
|
@ -60,6 +62,6 @@ pub fn json<T: Serialize>(value: T, code: StatusCode) -> Response<Body> {
|
|||
Response::builder()
|
||||
.status(code)
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(Body::from(serialized))
|
||||
.body(Full::new(Bytes::from(serialized)))
|
||||
.unwrap()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue