小编Áko*_*dra的帖子

psql 扩展显示 - 避免破折号

当我有一个非常宽的列(如 json 文档)并且我使用扩展显示使内容至少部分可读时,我仍然看到非常丑陋的记录分隔符,它似乎想要与最宽的列一样宽,像这样:

有没有办法避开“破折号之海”?

-[ 记录 1]--+---------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -----------------------------------------

身份证 | 18

说明 | {json 数据 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}

参数 | {json 数据 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}

姓名 | 富

-[ 记录 2]--+---------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ------------------------------------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -----------------------------------------

身份证 | 19

说明 | {} …

postgresql psql

4
推荐指数
1
解决办法
820
查看次数

如果尚未设置,如何设置嵌套在多个选项中的值?

我有这样的配置设置:

#[derive(Debug, Deserialize, Serialize)]
struct Config {
    defaults: Option<Default>,
}

#[derive(Debug, Deserialize, Serialize)]
struct Default {
    duration: Option<Millis>,
}

#[derive(Serialize, Deserialize, Debug)]
struct Millis(u64);
Run Code Online (Sandbox Code Playgroud)

有一个值let cfg: &mut Config,我怎么能轻松地设置这个值的持续时间?

我试过这个,如果值不存在,它会恐慌:

*cfg.default.as_mut().unwrap().duration.as_mut().unwrap() = Millis(1234)
Run Code Online (Sandbox Code Playgroud)

unwrap除了这个,我还没有找到解决这些s 的方法来按需创建值,这更加冗长......

if cfg.defaults.is_none() {
    cfg.defaults = Some(Default { duration: None });
}

if cfg.defaults.as_mut().unwrap().duration.is_none() {
    cfg.defaults.as_mut().unwrap().duration = Some(Millis(1234));
}
Run Code Online (Sandbox Code Playgroud)

什么是“方法”来做到这一点?

config mutability rust

4
推荐指数
1
解决办法
253
查看次数

FnMut 似乎捕获了它的调用参数?

在 ffi(嵌入式)环境中,当 C 代码需要函数指针(和可选的,通常是 *void 参数)时,通常会使用蹦床,但我们希望让它调用 rust 闭包。

蹦床是一个fn,而一个盒装闭包作为参数提供。fn 代码只是调用闭包。

然而,我似乎无法让借用检查器相信以下代码是安全的,并且似乎认为在对闭包的调用返回后,作为参数给闭包提供的引用(未由闭包捕获)仍然是借用的。

我不确定为什么会出现这种情况,有人可以帮忙如何编译吗?

// Workaround for unstable feature 'trait_alias'
pub trait Callback<'a>: FnMut(&'a mut Context<'a>) {}

impl<'a, T> Callback<'a> for T where T: FnMut(&'a mut Context<'a>) {}

pub fn trampoline(cb_ptr: *mut c_void ) {
    let s = "foo";
    let mut ctx = Context { s };

    unsafe {
        let cb = cb_ptr as *mut Box<dyn Callback<'_>>;
        (*cb)(&mut ctx);
    }

    let Context { s, .. } = ctx;

    info!("s = …
Run Code Online (Sandbox Code Playgroud)

rust

4
推荐指数
1
解决办法
70
查看次数

C# 阻塞等待响应

我多次偶然发现这个问题,主要是通过 hacks 解决它,但希望看到一种“正确”的方法来做到这一点。

我正在编写一个通信协议,与 RPC 非常相似,我的端点提出“查询”,他们收到“回复”。

现在...我想实现一个名为 SendCommand 的函数,它会发出一个查询,等待对该问题的回复,然后返回它。

所以我可以做类似的事情

int outside_temp = SendCommand(What is the temperature outside).ToInt();
Run Code Online (Sandbox Code Playgroud)

这样做的问题是消息是异步发送和接收的,事件通知我新消息已经到达,以及它是什么。我需要阻塞线程,直到对提到的查询的回复到达,提取其数据内容,并将其返回给调用者。

我的问题是阻塞线程。阻塞线程不是问题,我们谈论的是多线程应用程序,因此 UI 不会冻结等,但问题是实现此目的的正确方法是什么?

我正在考虑在 SendCommand 函数中初始化一个信号量,等待它,并在消息接收到的事件处理程序中释放信号量(在检查它是正确的消息之后)?

问候, axos88

.net c# events multithreading blocking

2
推荐指数
1
解决办法
7529
查看次数

C++ 11移动构造函数优化

我目前正试图抓住移动构造函数.我发现了以下内容(编译使用g++ d.cpp --std=c++11 -O3)

class A {
    string _x;
public:
  A(string x) { cout << "default contrsutctor: " << x << "\n"; _x = x; }
  A(const A& other) { cout << "copy contrsutctor: " << other._x << "\n"; _x = other._x;  }
  A(A&& other) { cout << "move contrsutctor: " << other._x << "\n"; _x = other._x;  }

  A foo() {
    cout << "foo: " << _x << "\n";
    return A("foo");
  }
};

int main()
{
  A …
Run Code Online (Sandbox Code Playgroud)

c++ move-semantics c++11

2
推荐指数
2
解决办法
345
查看次数