我需要以最少的仪式获得一个简单的JSON序列化解决方案.所以我很高兴找到即将推出的Play 2.2库.这与普通案例类完美匹配,例如
import play.api.libs.json._
sealed trait Foo
case class Bar(i: Int) extends Foo
case class Baz(f: Float) extends Foo
implicit val barFmt = Json.format[Bar]
implicit val bazFmt = Json.format[Baz]
Run Code Online (Sandbox Code Playgroud)
但是以下失败了:
implicit val fooFmt = Json.format[Foo] // "No unapply function found"
Run Code Online (Sandbox Code Playgroud)
我如何设置所谓的缺失提取器Foo?
或者你会推荐任何其他独立的库,或多或少全自动处理我的情况?我不关心是在编译时使用宏还是在运行时使用反射,只要它开箱即用即可.
我注意到取决于共享库的应用程序失败:如果您缺少某些依赖项,即使用户无意使用依赖项的功能,应用程序也会在加载时失败.
我希望我的应用程序比这更好.理想情况下,而不是分配n个不同的包,其中n = numberOfSupportedArchitectures*numberOfSupportedOS*Π(对于每个共享库)(备选方案的数量) 我会在加载时发出"加载共享库时出错"异常我想 - 但不需要 - 的库被发现不存在,然后以一种简单避免使用未解决的链接的方式继续执行.但显然,人们无法捕捉到这一点.如果缺少某些东西,那么在main()开始之前它都会崩溃.
我可以控制加载过程最接近的是使用dlopen,dlsym等解决所有链接.太无聊了.我希望有一个图书馆可供我这样做吗?
我注意到这不会是基于源的发行版或Windows上的问题.我打算在标签中放入二进制包,但显然我没有硬币标签的代表.
'似乎最优雅的解决方案在于改进OS的加载器/链接器的行为.
use std::iter::Iterator;
trait ListTerm<'a> {
type Iter: Iterator<Item = &'a u32>;
fn iter(&'a self) -> Self::Iter;
}
enum TermValue<'a, LT>
where
LT: ListTerm<'a> + Sized + 'a,
{
Str(LT),
}
Run Code Online (Sandbox Code Playgroud)
error[E0392]: parameter `'a` is never used
--> src/main.rs:8:16
|
8 | enum TermValue<'a, LT>
| ^^ unused type parameter
|
= help: consider removing `'a` or using a marker such as `std::marker::PhantomData`
Run Code Online (Sandbox Code Playgroud)
'a显然正在被使用.这是一个错误,还是参数枚举还没有真正完成?rustc --explain E0392建议使用PhantomData<&'a _>,但我认为在我的用例中没有任何机会这样做.
似乎我们可以简单地得到小于的浮点数numeric_limits<float>::min().为什么.如果numeric_limits<float>::min()不应该是最小的正浮动,它应该是什么?
#include <iostream>
#include <limits>
using namespace std;
int main(){
float mind = numeric_limits<float>::min();
float smaller_than_mind = numeric_limits<float>::min()/2;
cout<< ( mind > smaller_than_mind && smaller_than_mind > 0 ) <<endl;
}
Run Code Online (Sandbox Code Playgroud)
我在支架内的https://api.flutter.dev/flutter/widgets/RichText-class.html的 Centered 中有一个常规的普通富文本小部件。我看不到它。我什么也看不见。调试工具显示富文本确实存在于小部件层次结构中(尽管我看不到其中的 TextSpan,大概它们就在那里。)
Scaffold(body: Center(child:
RichText(
text: TextSpan(
text: 'Hello ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(text: ' world!'),
],
),
),
));
Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <cmath>
#include <sstream>
using namespace std;
int main(){
stringstream ss;
double ad = 7.63918e-313;
ss << ad;
cout<<ss.str()<<endl;
//you will see that the above double is valid, and maps to the specified string
//but stod cannot map it back
stod("7.63918e-313");
//terminate called after throwing an instance of 'std::out_of_range'
}
Run Code Online (Sandbox Code Playgroud)
在此处运行:https://onlinegdb.com/Sy1MT1iQM
"7.63918e-313"将序列化一个double,但是stod不能反序列化它.这里发生了什么?可能的最小双倍大约是10 ^ -324.
stdlib中是否有一对函数能够可靠地从字符串化中来回映射双精度?不应该吗?
情节变粗.我们有两个奇怪的观察.
std::numeric_limits<double>::min() stod也无法解析.
std::numeric_limits<double>::min()不是最小的双倍.我们的双倍小,我发现我们可以通过简单地分割min来获得更小的双打,所以这不是我的双重异常或任何东西https://onlinegdb.com/rJvilljQz
我很担心.
#include <iostream>
#include <thread>
using namespace std;
thread&& launch(){
thread launchee([](){
this_thread::sleep_for(chrono::milliseconds(280));
cout<<"HA!"<<endl;
});
return move(launchee);
}
int main(int argc, char **argv){
thread mine(launch());
mine.join();
}
Run Code Online (Sandbox Code Playgroud)
用.编译 g++-4.6 -std=c++0x 1.cpp -o e1 -pthread
输出"在没有活动异常的情况下调用终止",然后程序中止.
这应该工作,不应该吗?