我只想检索当前的时间和日期并将其存储在一个变量中。为此,我尝试使用 chrono::DateTime。
在文档中,我发现了这一点:
use chrono::{DateTime, TimeZone, NaiveDateTime, Utc};
let dt = DateTime::<Utc>::from_utc(NaiveDate::from_ymd(2016, 7, 8).and_hms(9, 10, 11), Utc);
Run Code Online (Sandbox Code Playgroud)
这让我可以存储特定的日期和时间,但我无法弄清楚如何检索实际的当前日期和时间并将其放入我的日期时间变量中。
首先,我想提一下,StackOverflow 和网络上有很多类似的问题,但我只是不知道如何针对我的情况解决此错误。
所以我有一个结构,它代表我自己的错误类型:
#[derive(Debug)]
pub struct Error {
msg: String,
}
Run Code Online (Sandbox Code Playgroud)
然后我继续实施Display并std::error::Error针对我的错误类型:
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.msg)
}
}
impl std::error::Error for Error {
fn description(&self) -> &str {
&self.msg
}
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试实现,std::convert::From以便我可以与运算符无缝地使用我的错误类型?:
impl From<dyn std::error::Error> for Error {
fn from(err: dyn std::error::Error) -> Self {
Error {
msg: err.to_string(),
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是 rust 编译器给了我这个错误:
error[E0277]: the size for values …Run Code Online (Sandbox Code Playgroud) 我正在使用 Actix 框架来创建一个简单的服务器,并且我已经使用一个简单的 HTML 前端实现了文件上传。
use actix_web::web::Data;
use actix_web::{middleware, web, App, HttpResponse, HttpServer};
use std::cell::Cell;
// file upload functions, the same as you can find it under the
// actix web documentation:
// https://github.com/actix/examples/blob/master/multipart/src/main.rs :
mod upload;
fn index() -> HttpResponse {
let html = r#"<html>
<head><title>Upload Test</title></head>
<body>
<form target="/" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" value="Submit"></button>
</form>
</body>
</html>"#;
HttpResponse::Ok().body(html)
}
#[derive(Clone)]
pub struct AppState {
counter: Cell<usize>,
}
impl AppState {
fn new() -> Result<Self, Error> …Run Code Online (Sandbox Code Playgroud) 所以我试图在执行 php 文件时为网页加载屏幕,因为 php 文件从 MYSQL 服务器获取数据,有时可能需要一段时间。
所以我的 php 文件被命名为“connect.php”并回显 html 代码,并且在调用时不需要任何参数。这是一个简单的概述,以便您了解它的作用。当我不使用 AJAX 并正常包含它时,整个文件就可以工作。
<?php
if (!$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') die('Invalid request');
//MYSQL-Connection
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo //// Some HTML Code
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
Run Code Online (Sandbox Code Playgroud)
在我的 index.php 中,我使用 AJAX 来调用 php 文件:
<section id="intro" class="wrapper style1">
<style>#loading { display:none; }</style>
<div id="loading">Test</div>
<div class="container">
<span>
<script>
$( '#loading' ).show(); …Run Code Online (Sandbox Code Playgroud) 我遇到输入溢出的问题,我不知道如何管理它。所以让我给你我的代码并解释一下:
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=1, rate=SAMPLERATE, input_device_index=chosen_device_index, input=True, frames_per_buffer=CHUNK)
frames = []
for i in range(0, int(SAMPLERATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
decoded = np.frombuffer(data, 'int16')
mfcc_feat = mfcc(decoded, samplerate=SAMPLERATE/3, winlen=WINDOW_SIZE, winstep=WINDOW_STEP, nfft=NFFT)
if len(frames) < 299:
frames.append(mfcc_feat)
elif len(frames) >= 299:
predict_test = tf.convert_to_tensor(frames)
result = model.predict(predict_test)
frames = []
frames.append(mfcc_feat)
stream.stop_stream()
stream.close()
p.terminate()
Run Code Online (Sandbox Code Playgroud)
所以基本上我在这里所做的就是使用经过训练的张量流模型来预测实时生成的音频特征。
首先我打开一个流。然后我使用 for 循环读取该流中的音频数据。当我将采样率设置为 48000 并将块大小设置为 192 每秒 250 次时,就会发生这种情况。因此,我每秒读取下一个块 250 次,使用它进行解码numpy.frombuffer,然后计算特征。特征存储在数组中frames。每次,frames数组的长度为299,我将使用该数组通过我的张量流模型进行预测。 …
我目前正在使用 Rust 和 Actix-Web 实现一个服务器。我现在的任务是每 10 秒从这台服务器向另一台服务器发送一个请求(ping 请求)。ping 请求本身是在一个async函数中实现的:
async fn ping(client: web::Data<Client>, state: Data<AppState>) -> Result<HttpResponse, Error> {}
Run Code Online (Sandbox Code Playgroud)
这是我的简单服务器主功能:
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
::std::env::set_var("RUST_LOG", "debug");
env_logger::init();
let args = config::CliOptions::from_args();
let config =
config::Config::new(args.config_file.as_path()).expect("Failed to config");
let address = config.address.clone();
let app_state = AppState::new(config).unwrap();
println!("Started http server: http://{}", address);
HttpServer::new(move || {
App::new()
.data(app_state.clone())
.app_data(app_state.clone())
.data(Client::default())
.default_service(web::resource("/").route(web::get().to(index)))
})
.bind(address)?
.run()
.await
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用tokio,但这太复杂了,因为所有不同的异步函数及其生命周期。
那么在服务器启动后每 10 秒,actix-web 中是否有任何简单的方法来执行此 ping 功能(可能作为服务)?
谢谢!
所以我有一个结构数组:
typedef struct {
float x;
float y;
float z;
} Point;
const int SIZE = 16;
Point* points;
points = malloc(SIZE * sizeof(Point));
Run Code Online (Sandbox Code Playgroud)
现在我还有一个数组结构:
typedef struct {
float* vectorX;
float* vectorY;
float* vectorZ;
} arrayStruct;
arrayStruct myArrayStruct;
// Allocate Memory
myArrayStruct.vectorX = _aligned_malloc(sizeof(float)* SIZE, 32);
myArrayStruct.vectorY = _aligned_malloc(sizeof(float)* SIZE, 32);
myArrayStruct.vectorZ = _aligned_malloc(sizeof(float)* SIZE, 32);
Run Code Online (Sandbox Code Playgroud)
所以现在我的问题是:是否有一种快速/简单的方法可以使用 SIMD(内在函数)将 AoS(结构数组)转换为数组结构?
我有以下问题:
首先我有结构:
struct Filehandler
{
const int id = 1;
};
Run Code Online (Sandbox Code Playgroud)
然后我有两种方法 - 一种用于创建新的 Filehandler 结构,另一种用于删除该结构。因为整个代码是 Rust 项目的 Webassembly 插件的一部分,所以我必须使用指针。
所以这是我分配结构的方法:
uintptr_t newhandler() {
struct Filehandler* filehandler = (struct Filehandler*) malloc(sizeof(struct Filehandler));
uintptr_t *ptr = (uintptr_t *)&filehandler;
uintptr_t temp = (uintptr_t)ptr;
return temp;
}
Run Code Online (Sandbox Code Playgroud)
我知道这在某种程度上看起来令人困惑,但我必须检索指针指向的地址作为值。这就是为什么我将我的指针作为值返回。
现在我想创建一个删除结构的函数。作为参数,函数得到一个uintptr_t:
void destroy_handler(uintptr_t ptr) {
........?
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:是否可以删除 Struct filehandler,如果我有一个指向它的指针存储在 a 中uintptr_t,并将其作为destroy_handler函数的值。如果这是可能的,我该怎么做?
谢谢你们!