我使用自制软件来安装GCC 4.7.0,我的项目的make在汇编时失败了.我可以成功地从.c - > .s中获取代码,但是.s - > .o失败了.
要查看用于安装GCC的brew配方,请查看:https://github.com/Homebrew/homebrew-dupes/blob/master/gcc.rb.我还使用https://github.com/mxcl/homebrew/blob/master/Library/Formula/binutils.rb从上游安装了binutils .安装binutils似乎没有在/ usr/local/lib或类似的地方引入新的'as'.
如何找到这个缺失的指令错误?看起来编译器是正确的,但链接器根本不支持这些指令.说明似乎是矢量指令.
xavierlange $> make suricata.o
/usr/local/bin/gcc-4.7 -DHAVE_CONFIG_H -I. -I.. -I../libhtp -I/opt/local/include -v -Wextra -Wall -fno-strict-aliasing -fno-tree-pre -Wno-unused-parameter -std=gnu99 -DOS_DARWIN -march=native -DLIBPCAP_VERSION_MAJOR=1 -DHAVE_PCAP_SET_BUFF -DUNITTESTS -DREVISION="61d5fe3" -MT suricata.o -MD -MP -MF .deps/suricata.Tpo -c -o suricata.o suricata.c
Using built-in specs.
COLLECT_GCC=/usr/local/bin/gcc-4.7
Target: x86_64-apple-darwin11.3.0
Configured with: ../configure --enable-languages=c,c++,fortran,java,objc,obj-c++ --prefix=/usr/local/Cellar/gcc/4.7.0/gcc --datarootdir=/usr/local/Cellar/gcc/4.7.0/share --bindir=/usr/local/Cellar/gcc/4.7.0/bin --program-suffix=-4.7 --with-gmp=/usr/local/Cellar/gmp/5.0.4 --with-mpfr=/usr/local/Cellar/mpfr/3.1.0 --with-mpc=/usr/local/Cellar/libmpc/0.9 --with-system-zlib --enable-stage1-checking --enable-plugin --enable-lto --disable-multilib --disable-nls
Thread model: posix
gcc version 4.7.0 …Run Code Online (Sandbox Code Playgroud) 我正在从文件中读取原始数据,我想将其转换为整数:
fn main() {
let buf: &[u8] = &[0, 0, 0, 1];
let num = slice_to_i8(buf);
println!("1 == {}", num);
}
pub fn slice_to_i8(buf: &[u8]) -> i32 {
unimplemented!("what should I do here?")
}
Run Code Online (Sandbox Code Playgroud)
我会在C中进行类型转换,但是我在Rust中做什么?
什么是一个惯用的方法来处理字节串nibblewise和漂亮打印其十六进制(0-F)表示?
putStrLn . show . B.unpack
-- [1,126]
Run Code Online (Sandbox Code Playgroud)
其中,经过进一步的工作
putStrLn . show . map (\x -> N.showIntAtBase 16 (DC.intToDigit) x "") . B.unpack
["1","7e"]
Run Code Online (Sandbox Code Playgroud)
但我真正想要的是
["1","7","e"]
Run Code Online (Sandbox Code Playgroud)
或者更好
['1','7','e']
Run Code Online (Sandbox Code Playgroud)
我可以捣乱["1","7e"]但是那个字符串操作,而我宁愿做数字操作.我是否需要下拉移动和屏蔽数值?
我正在使用Rusoto AWS Kinesis库的期货版本.我需要生成AWS Kinesis请求的深层管道以实现高吞吐量,因为Kinesis每个HTTP请求的限制为500条记录.结合发送请求的50ms延迟,我需要开始生成许多并发请求.我希望创建大约100个飞行请求的某个地方.
Rusoto put_records函数签名如下所示:
fn put_records(
&self,
input: &PutRecordsInput,
) -> RusotoFuture<PutRecordsOutput, PutRecordsError>
Run Code Online (Sandbox Code Playgroud)
这RusotoFuture是一个像这样定义的包装器:
/// Future that is returned from all rusoto service APIs.
pub struct RusotoFuture<T, E> {
inner: Box<Future<Item = T, Error = E> + 'static>,
}
Run Code Online (Sandbox Code Playgroud)
内部Future是包裹但RusutoFuture仍然是工具Future::poll(),所以我相信它与futures-rs 生态系统兼容.在RusotoFuture提供了一个同步调用:
impl<T, E> RusotoFuture<T, E> {
/// Blocks the current thread until the future has resolved.
///
/// This is meant to …Run Code Online (Sandbox Code Playgroud) 我正在使用erlang作为服务之间的桥梁,我想知道人们有什么建议来处理被击落的连接?
我从本地文件中获取输入并将它们输出到AMQP,可以想象AMQP经纪人可能会崩溃.对于这种情况,我想继续重试连接到AMQP服务器,但我不想将CPU与这些连接尝试挂钩.我倾向于在重新启动AMQP代码时进行睡眠.难道"黑客"本能绕过快速失败并让erlang处理它的目的吗?更一般地说,是否应该使用erlang管理员行为来处理故障连接?
我用这个正则表达式处理格式为"1s:1d","100:5000"等的简单字符串:
let retention_matcher = regex::Regex::new({r"^(\d+)([smhdy])?:(\d+)([smhdy])?$"}).unwrap();
Run Code Online (Sandbox Code Playgroud)
我知道这个正则表达式应该只匹配一次所以我想运行正则表达式捕获并检查捕获的数量.
let iter = retention_matcher.captures_iter(ts);
let count = iter.count();
println!("iter.count(): {}", count);
let _ : Vec<Option<(u64,u64)>> = iter.map(|regex_match| {
let retval = retention_spec_to_pair(regex_match);
println!("precision_opt: {:?}", retval);
retval
}).collect();
Run Code Online (Sandbox Code Playgroud)
问题是该count()方法移动iter,我不能再使用它.
src/bin/whisper.rs:147:42: 147:46 error: use of moved value: `iter`
src/bin/whisper.rs:147 let _ : Vec<Option<(u64,u64)>> = iter.map(|regex_match| {
^~~~
src/bin/whisper.rs:144:21: 144:25 note: `iter` moved here because it has type `regex::re::FindCaptures<'_, '_>`, which is non-copyable
src/bin/whisper.rs:144 let count = iter.count();
Run Code Online (Sandbox Code Playgroud)
这对我来说没有意义.count方法是否应该返回可复制usize值而不是移动 …
如何获取a Vec<Option<T>>,T无法复制的位置以及展开所有Some值?
我在这map一步中遇到了错误.我很高兴移动原始列表的所有权并"扔掉" Nones.
#[derive(Debug)]
struct Uncopyable {
val: u64,
}
fn main() {
let num_opts: Vec<Option<Uncopyable>> = vec![
Some(Uncopyable { val: 1 }),
Some(Uncopyable { val: 2 }),
None,
Some(Uncopyable { val: 4 }),
];
let nums: Vec<Uncopyable> = num_opts
.iter()
.filter(|x| x.is_some())
.map(|&x| x.unwrap())
.collect();
println!("nums: {:?}", nums);
}
Run Code Online (Sandbox Code Playgroud)
这给出了错误
error[E0507]: cannot move out of borrowed content
--> src/main.rs:17:15
|
17 | .map(|&x| x.unwrap())
| ^-
| ||
| …Run Code Online (Sandbox Code Playgroud) 我想实现fmt::Display我的代码中常用的嵌套结构.
// The root structure
pub struct WhisperFile<'a> {
pub path: &'a str,
pub handle: RefCell<File>,
pub header: Header
}
pub struct Header{
pub metadata: metadata::Metadata,
pub archive_infos: Vec<archive_info::ArchiveInfo>
}
pub struct Metadata {
// SNIP
}
pub struct ArchiveInfo {
// SNIP
}
Run Code Online (Sandbox Code Playgroud)
如您所见,这是一个非平凡的数据树.当呈现为一行时,该archive_infos属性Header可以很长.
我想发布一些东西
WhisperFile ({PATH})
Metadata
...
ArchiveInfo (0)
...
ArchiveInfo (N)
...
Run Code Online (Sandbox Code Playgroud)
但是当我尝试显示时,Vec<ArchiveInfo>我得到的显示没有实现.我可以实现fmt::Display,ArchiveInfo但这还不够,因为fmt::Display没有为父容器实现Vec.如果我实现FMT ::显示collections::vec::Vec<ArchiveInfo>我得到the impl does not …
我需要在主机上的所有可用地址上发送相同的多播UDP数据包.我需要发送到localhost/ 127.0.0.1和239.255.0.1.std从版本1.2开始,Rust的lib已经弃用了多播行为,无论如何,为了获得我需要的特性,我必须切换到更完整的行为net2.
该net2API有一堆的UDP扩展其提供我正在寻找的API.我特别感兴趣
fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> Result<()>
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何处理multiaddr vs interface.我以为我会给multiaddr 127.0.0.1或者239.255.0.1如何找到interface参数的有效IPv4 ?有一个Rust函数,在某个地方,可以提供一个Vec<Ipv4Addr>?我需要解析输出ifconfig吗?
这是一个独立的程序,它发出我的公共接口(必须192.168.0.102手动找到该地址):
extern crate net2;
use std::net::{ UdpSocket, Ipv4Addr };
use net2::UdpSocketExt;
fn main() {
let sock = UdpSocket::bind("0.0.0.0:2345").unwrap();
let local_addr = Ipv4Addr::new(192, 168, 0, 102);
let multicast_addr = Ipv4Addr::new(239, 255, 0, 1);
sock.join_multicast_v4(&multicast_addr, &local_addr).unwrap();
}
Run Code Online (Sandbox Code Playgroud)
如果这有任何区别,我正在编制夜莺.
获得访问权限的最有效方法是什么&mut [u8]?现在我从 Vec 借用,但更直接地分配缓冲区会更容易。
我现在能做的最好的事情是预先分配一个向量,然后推出它的长度,但这不可能是惯用的。
let mut points_buf : Vec<u8> = Vec::with_capacity(points.len() * point::POINT_SIZE);
for _ in (0..points_buf.capacity()) {
points_buf.push(0);
}
file.read(&mut points_buf[..]).unwrap();
Run Code Online (Sandbox Code Playgroud) rust ×7
iterator ×2
slice ×2
arrays ×1
assembly ×1
asynchronous ×1
behavior ×1
buffer ×1
bytestring ×1
casting ×1
erlang ×1
future ×1
gcc ×1
gen-server ×1
haskell ×1
hex ×1
igmp ×1
macos ×1
multicast ×1
mutable ×1
optional ×1
osx-lion ×1
pretty-print ×1
printf ×1
regex ×1
sockets ×1
traits ×1
udp ×1