小编Ehs*_*ani的帖子

安装RMySQL时出错(在Ubuntu 14.04中为MySQL 5.5.37)

每次我尝试安装RMySQL时都会出现以下错误:

Installing package into ‘/home/ehsan/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
* installing *source* package ‘RMySQL’ ...
** package ‘RMySQL’ successfully unpacked and MD5 sums checked
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking …
Run Code Online (Sandbox Code Playgroud)

ubuntu r rmysql

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

多维数据集根整数?

这似乎很简单,但我找不到办法.我需要显示整数的立方根是否为整数.我is_integer()在Python 3.4中使用了float方法但是没有成功.如

x = (3**3)**(1/3.0) 
is_integer(x)    
True
Run Code Online (Sandbox Code Playgroud)

x = (4**3)**(1/3.0) 
is_integer(x)    
False
Run Code Online (Sandbox Code Playgroud)

我想x%1 == 0,x == int(x)isinstance(x,int)没有成功.

我很感激任何评论.

python python-3.x

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

具有幻影生命周期的结构有什么意义?

我正在浏览一些库,我注意到使用了一个包含幻影生命周期字段的结构,比如

struct S<'a> {
    s: i32,
    _lifetime: PhantomData<&'a ()> // NOTE: there's no generic type here!
}
Run Code Online (Sandbox Code Playgroud)

我很想知道幻影生命周期的重要性——它提供了什么好处S,没有它就不可能或不方便处理?

rust

3
推荐指数
1
解决办法
961
查看次数

为什么联合上的模式匹配具有无法访问的模式警告?

鉴于文档,我无法理解为什么联合上的模式匹配不能正常工作:

union A {
    a1: i32,
    a2: f32,
}

struct B(A);
let b = B(A { a2: 1.0 });
unsafe {
    match b.0 {
        A { a1 } => println!("int"),
        A { a2 } => println!("float"),
    }
}
Run Code Online (Sandbox Code Playgroud)

输出带有无法访问警告的"int".

warning: unreachable pattern
  --> src/main.rs:12:13
   |
12 |             A { a2 } => println!("float"),
   |             ^^^^^^^^
   |
   = note: #[warn(unreachable_patterns)] on by default
Run Code Online (Sandbox Code Playgroud)

pattern-matching rust

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

通过FFI获取和设置上一条错误消息的正确方法是什么?

我正在包装一个C API(dylib),它为最后一条错误消息公开了一个setter和getter API:

extern "C" {
    /// GetLastError is thread-safe
    pub fn GetLastError() -> *const ::std::os::raw::c_char;
    pub fn SetLastError(msg: *const ::std::os::raw::c_char);
}
Run Code Online (Sandbox Code Playgroud)

包裹它们的最简单方法如下

use std::error::Error;
use std::ffi::CStr;
use std::fmt::{self, Display, Formatter};
use std::os::raw::c_char;

pub struct MyError;

impl MyError {
    pub fn get_last() -> &'static str {
        unsafe {
            match CStr::from_ptr(c_api::GetLastError()).to_str() {
                Ok(s) => s,
                Err(_) => "Invalid UTF-8 message",
            }
        }
    }

    pub fn set_last(msg: &'static str) {
        unsafe {
            c_api::SetLastError(msg.as_ptr() as *const c_char);
        }
    }
}

impl Display for …
Run Code Online (Sandbox Code Playgroud)

runtime-error ffi backtrace rust

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