C++/Rust Interop: Using Bridges in Practice
1 - New Rust Extends a C++ Project 5Large existing C++ Library New Plugin Existing Plugins 6C++ Header Class with Methods C++ Source Uses extern “C” from Rust Unsafe Rust C ABI Safe Rust hpp cpp std::unique_ptr<rust::Joint, deleter_from_fn> robot_joint_; }; } // namespace robot_joint hpp 10namespace robot_joint::rust { struct Joint; } // namespace robot_joint::rust extern "C" "C" { extern void robot_joint_free(robot_joint::rust::Joint*); } template struct deleter_from_fn { template constexpr void operator()(T* arg) const { fn(arg); } }; hpp 0 码力 | 45 页 | 724.12 KB | 5 月前3So You Think You Can Hash
@ciura_victor Victor Ciura Principal Engineer Rust Tooling @ Microsoft 🐘 @ciura_victor@hachyderm.io 🦋 @ciuravictor.bsky.social 🦀 So You Think You Can Hash CppCon September 20242024 Victor Visual C++ @ciura_victor 🐘 @ciura_victor@hachyderm.io 🦋 @ciuravictor.bsky.social Oxidizer SDK 🦀 Rust Tooling 🦀2024 Victor Ciura | @ciura_victor - Unleashing 🦀 The Ferris Within 4 Motivation Defined Range It is often desirable that the output of a hash function have fixed size. If, for example, the output is constrained to 32-bit integer values, the hash values can be used to index into an0 码力 | 119 页 | 6.54 MB | 5 月前3C++ Exceptions for Smaller Firmware
Set vsp = r[nnnn] 10110000 Finish 10000000 00000000 refuse to unwind / call std::terminate (for example, out of a cleanup) 123 Note: Instructions are in 8-bit segments Limit is 7 bytes 3 bytes typicallyARM func3() -> Result{ return Ok(13); } Using Rust rustc --target thumbv7em-none-eabi -C opt-level="s" --emit=obj rust.rs 18400000000 <rust::combined::h7a7b0cc556a62e18>: 0: b5f0 push 2c: e00b b 0x46 2e: 4668 mov r0, sp Return Rust: Disassembled! objdump --disassemble --demangle rust.o > rust.S 30: f7ff fffe bl 0x30 34: e9dd 0100 ldrd r0, r1, [sp] 0 码力 | 237 页 | 6.74 MB | 5 月前3Coroutines and Structured Concurrency in Practice
of structured concurrency • nursery in Python trio • task group in Python asyncio • task scope in Rust • coroutine scope in Kotlin • async_scope in nvidia/stdexec We also call it a nursery (mnemonics: or (re)throw an exception. bool await_ready() const noexcept Performance optimizationAwaitable example typedef void (*ares_addrinfo_callback)(void* arg, int status, struct ares_addrinfo_hints* hints, ares_addrinfo_callback, void* arg);Awaitable example class DNSQuery { ares_channel_t* channel; const char* name; struct sockaddr_in result;0 码力 | 103 页 | 1.98 MB | 5 月前3Expressive Compile-time Parsers
Popular parsing algorithms used in generators are LL, LL(k), LR, LR(k), LALR, GLR... EBNF grammar example: identifier = alphabetic character, { alphabetic character | digit } ; number = [ "-" ], digit, SQL • CSS • Regular Expressions (PCRE) • Make (makefile)DSL Example – Boost Spirit Boost Spirit library has a DSL for creating parsers. Example code from XML parser: text %= lexeme[+(char_ - '<')]; node The syntax must be valid C++ syntax because it needs to be parsed by the compiler >> node* >>Example – Filter Transform vectorcats = { /*...*/ }; vector< tuple > result; for(auto 0 码力 | 134 页 | 1.73 MB | 5 月前3Things Happening in SG14
is SG14? • There have already been some contributions to C++ due in part to SG14 efforts. For example: • Some raw memory algorithms from• std::uninitialized_default_construct(), std::uni some who write their own containers, for example 16What is SG14? • There have already been some contributions to C++ due in part to SG14 efforts. For example: • Some raw memory algorithms from is SG14? • There have already been some contributions to C++ due in part to SG14 efforts. For example: • Some raw memory algorithms from • std::flat_map and std::flat_set • [[likely]], [[unlikely]] 0 码力 | 148 页 | 1009.97 KB | 5 月前3Lifetime Safety in C++: Past, Present and Future
issues | ZDNET • Memory safety (chromium.org) • Implications of Rewriting a Browser Component in Rust - Mozilla Hacks - the Web developer blog • Google Online Security Blog: Memory Safe Languages in Profile Crubit: Adopting Rust’s Type System P2771: Thomas Neumann’s Dependency AnnotationsFuture of C++? C++ Core Guidelines’ Lifetime Safety Profile Crubit: Adopting Rust’s Type System P2771: Value SemanticsFuture of C++? C++ Core Guidelines’ Lifetime Safety Profile Crubit: Adopting Rust’s Type System P2771: Thomas Neumann’s Dependency Annotations Vale: Generational References +0 码力 | 124 页 | 2.03 MB | 5 月前3Iteration Revisited
iteration is complete ▸ Read the element corresponding to the state ▸ Advance the iteration state } Rust iterators: next() -> optional16ITERATION REVISITED ITERATION FUNDAMENTALS 17ITERATION REVISITED more adaptors, and then finishes with a call to an algorithm 30ITERATION REVISITED FLUX PIPELINE EXAMPLE std�::vector vec = get_vector(); int max_even_sq = flux�::ref(vec) �// iterate .value_or(0); �// handle empty sequences 31ITERATION REVISITED FLUX PIPELINE EXAMPLE std�::vector vec = get_vector(); int max_even_sq = flux�::ref(vec) �// iterate 0 码力 | 56 页 | 5.27 MB | 5 月前3C++高性能并行编程与优化 - 课件 - 15 C++ 系列课:字符与字符串
这个特殊的名字空间里包含了所有的 operator“” 函数。 小彭老师锐评:何谓“键盘压力” • 高情商:键盘压力,指的是程序员敲击键盘时产生的心理压力。 • 低情商:键盘压力,指的是 rust 键盘侠对 cpp 标准委员会的压力。 • rust 键盘侠曰:我们有 233_i32 , cpp 做得到吗? • cpp 标准委员会:谢邀,人在 cpp14 ,已经在 operator“”_i32 了。 • 其实 cpp namespace ,不会存在强迫别人接受你的那一套后缀名规范。 • 甚至可以自定义一个 class int32 具有成员函数,然后就可以快乐地 233_i32 .some_method() 了。而 rust 这种预先规定好一些后缀,就只能是他们标准库的那 个 int32 ,不能自己定义了。 • 所以 cpp 之父曾经说,他设计 cpp11 的时候,是考虑“如何在对语言本身改动最小的情况下 ,尽量只 }; • void cihou_array(FatPtr fptr); • 这就是 rust 炫耀已久的数组胖指针。 C++20 中的 span 也是这个思想。 • 他提倡把 ptr 和 len 这两个逻辑上相关的参数绑在一起,避免程序员犯错。 用胖指针表示字符串 • 其实胖指针的思想既不是 rust 原创的,也不是 C++20 以后才出现的。 • 为了表示动态长度的数组, C++ 中的 vector0 码力 | 162 页 | 40.20 MB | 1 年前3Cooperative C++ Evolution
JavaScript, C++, Objective-C) C++ examples CCured*, CFlat*, CNatural**, Cyclone**, D*, .NET*, Rust*… — C++11/14/17/20/23 Dart* ES 4, Python 3 TypeScript Swift ES 2-10 (except 4) C99/11/17, Python JavaScript, C++, Objective-C) C++ examples CCured*, CFlat*, CNatural**, Cyclone**, D*, VB.NET*, Rust*… — C++11/14/17/20/23 Dart* ES 4, Python 3 TypeScript Swift ES 2-10 (except 4) C99/11/17, Python JavaScript, C++, Objective-C) C++ examples CCured*, CFlat*, CNatural**, Cyclone**, D*, VB.NET*, Rust*… — C++11/14/17/20/23 Dart* ES 4, Python 3 TypeScript Swift ES 2-10 (except 4) C99/11/17, Python0 码力 | 85 页 | 5.73 MB | 5 月前3
共 288 条
- 1
- 2
- 3
- 4
- 5
- 6
- 29