Relative Content

Tag Archive for rust

Split string on boundaries in Rust

Is there a nice (ideally built in or in itertools) way to split a &str on boundaries? For example I want to split where c.is_alphanumeric() or c.is_whitespace() changes.

Rust generic function with argument copy or borrow depending on concrete type

Is there any way to define a function in Rust with a generically-typed argument which will either copy or (immutably) borrow the argument depending on whether its concrete type is a Copy type? If that requires a macro, how might one go about writing such a macro–can they be invoked with knowledge of the concrete type being used at compile time?

Rust generic function with argument copy or borrow depending on concrete type

Is there any way to define a function in Rust with a generically-typed argument which will either copy or (immutably) borrow the argument depending on whether its concrete type is a Copy type? If that requires a macro, how might one go about writing such a macro–can they be invoked with knowledge of the concrete type being used at compile time?

Running llama.cpp server from a rust tokio thread

use actix_web::{get, post, web, App, HttpServer, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; use env_logger::Env; use log::info; #[get(“/”)] async fn hello() -> impl Responder { info!(“Request received”); “Hello, world!” } #[post(“/health”)] async fn echo(req_body: String) -> impl Responder { format!(“You sent: {}”, req_body) } #[derive(Deserialize)] struct Info { name: String, } #[derive(Serialize)] struct Greeting { message: String, […]