我想创建一个trait强制Result<T, E>某些函数的返回类型,但我无法弄清楚定义它的语法.
我已经达到了:
pub type NamedResult<T, E> = Result<T, E>;
pub trait Foo {
fn bar<T, E>(&self) -> NamedResult<T, E>;
}
pub struct Thing;
impl Foo for Thing {
pub fn bar<T, E>(&self) -> NamedResult<T, E> {
Ok(78i32)
}
}
Run Code Online (Sandbox Code Playgroud)
产生以下错误:
error: mismatched types:
expected 'T',
found 'i32'
(expected type parameter, found i32) [E0308]
Run Code Online (Sandbox Code Playgroud)
所以我接着尝试了:
pub fn bar<i32, String>(&self) -> NamedResult<i32, String> {
Ok(78i32)
}
Run Code Online (Sandbox Code Playgroud)
并收到以下错误:
error: user-defined types or type parameters cannot shadow the primitive …Run Code Online (Sandbox Code Playgroud) 我正在尝试发送一个JSON文件来进行一些测试.我有一个简单的测试文件,可以创建一个多维数组.这是测试文件:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$user['Mongo'] = null;
$user['Facebook'] = 12345;
$user['Twitter'] = null;
$user['Foursquare'] = null;
$user['Google'] = null;
$user['Name'] = "Bill Gates";
$user['Sex'] = 'M';
$user['Age'] = 26;
$user['Birthday'] = "1985-08-13";
$user['Friends'][0]['Mongo'] = null;
$user['Friends'][0]['Facebook'] = 123456;
$user['Friends'][0]['Twitter'] = null;
$user['Friends'][0]['Foursquare'] = null;
$user['Friends'][0]['Google'] = null;
$user['Friends'][0]['Name'] = "John Smith";
$user['Friends'][0]['Relationship'] = "Open";
$user['Friends'][1]['Mongo'] = null;
$user['Friends'][1]['Facebook'] = 1234567;
$user['Friends'][1]['Twitter'] = null;
$user['Friends'][1]['Foursquare'] = null;
$user['Friends'][1]['Google'] = null;
$user['Friends'][1]['Name'] = "Martina McBride";
$user['Friends'][1]['Relationship'] = "Open";
$user_json = json_encode($user); …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Webflux + R2DBC 将一些数据插入数据库。
调用数据->放入数据库->返回数据。
控制器
@RestController
public class UtilController {
private final FooService service;
@Autowired
public UtilController(FooService service) { this.service = service; }
@GetMapping(path = "/load-data")
public Mono<List<Foo>> loadFoos() { return service.addFoos(); }
}
Run Code Online (Sandbox Code Playgroud)
服务
public Mono<List<Foo>> addFoos() {
return webClient.getSomeStuff()
.map(results -> results.stream()
.map(/* ...transform to domain model */)
.toList())
.map(foos -> {
// This is the problem site.
List<Foo> buf = new ArrayList<>();
foos.forEach(f -> {
fooDao.createFoo(l)
.doOnNext(buf::add)
.next()
.subscribe();
});
return buf;
});
} …Run Code Online (Sandbox Code Playgroud) 我正在开发一个项目,我正在使用PHPExcel库来做一些事情.我今天遇到了第一个问题.读取和写入Excel工作很好,但后来我开始从Excel工作表中取出,然后进入Mongo.我基本上从Excel中读取了一些数组,然后尝试将该数组保存到Mongo中$collection->insert($array);
我有一个异常告诉我它无法插入任何零字符键.我var_dum()在我的阵列上做了一个看看它在世界上哪里得到一个空白键,这就是转储产生的.
array(10)
{
["um"]=> string(2) "EA"
["desc"]=> string(37) "FRAME WELDMENT, NITRATE REMOVAL TANKS"
["vws_num"]=> NULL
["part_num"]=> string(10) "SD-0408-01"
["manufac"]=> object(PHPExcel_RichText)#665 (1)
{
["_richTextElements" : "PHPExcel_RichText" : private]=> array(3)
{
[0]=> object(PHPExcel_RichText_TextElement)#184 (1)
{
["_text":"PHPExcel_RichText_TextElement":private]=> string(23) "VEOLIA WATER SOLUTIONS "
}
[1]=> object(PHPExcel_RichText_Run)#179 (2)
{
["_font":"PHPExcel_RichText_Run":private]=> object(PHPExcel_Style_Font)#183 (12)
{
["_name":"PHPExcel_Style_Font":private]=> string(5) "SWGDT"
["_size":"PHPExcel_Style_Font":private]=> string(2) "10"
["_bold":"PHPExcel_Style_Font":private]=> bool(false)
["_italic":"PHPExcel_Style_Font":private]=> bool(false)
["_superScript":"PHPExcel_Style_Font":private]=> bool(false)
["_subScript":"PHPExcel_Style_Font":private]=> bool(false)
["_underline":"PHPExcel_Style_Font":private]=> string(4) "none"
["_strikethrough":"PHPExcel_Style_Font":private]=> bool(false)
["_color":"PHPExcel_Style_Font":private]=> object(PHPExcel_Style_Color)#186 (4)
{
["_argb":"PHPExcel_Style_Color":private]=> string(8) "FF000000"
["_isSupervisor":"PHPExcel_Style_Color":private]=> bool(false) …Run Code Online (Sandbox Code Playgroud) 我试图用一个覆盖典型的jQuery Mobile背景.jpg.在我的生活中,我不能想到这一点.它让我疯了!我一直都在SO和谷歌对任何人的答案都无济于事.
我当前的标题信息
<head>
<title>Veolia Water Splash Guide</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"/>
<link rel="stylesheet" href="./css/stylo.css"/>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<script src="./js/main.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
我的应用程序遵循的过程:
index.html 加载图片淡入.(这个CSS覆盖工作完美)$.mobile.changePage()另一个页面,而不是多页格式这是我的CSS
#logo
{
position: absolute;
top: 0;
bottom: 0;
margin: auto;
width: 80%;
}
body
{
background: url('../img/background.jpg') !important;
background-repeat:repeat-y !important;
background-position:center center !important;
background-attachment:scroll !important;
background-size:100% 100% !important;
}
.ui-page .ui-body-c .ui-page-active .ui-overlay-c .ui-mobile-viewport
{
background: transparent !important;
}
Run Code Online (Sandbox Code Playgroud)
任何人都有一些指示或知道我做错了什么?背景闪烁一瞬间,然后被抛出......
在此先感谢您的帮助!
我在弄清楚为什么rustc假设我要使用collection::string::String而不是时遇到了一些麻烦std::string::String。
我没有直接使用它的声明,并且有特定的使用声明
这是我的条板箱根的简化版本:
extern crate serialize;
extern crate collections;
use std::str;
use std::string::String;
use std::io::{TcpListener, TcpStream};
use std::io::{Listener, Acceptor};
use self::serialize::json;
use self::serialize::json::Json;
use self::collections::tree_map::TreeMap;
use self::socket::Socket;
use self::socket::event::Event;
use self::socket::action::Action;
use self::socket::message::{Message, Text, Binary};
use self::server::Server;
use self::httpheader::{RequestHeader, ReturnHeader};
use self::socketmessenger::SocketMessenger;
pub mod socket;
pub mod server;
mod httpheader;
mod socketmessenger;
Run Code Online (Sandbox Code Playgroud)
这是我的mod抛出错误的顶部:
extern crate "rust-crypto" as rust_crypto;
use self::rust_crypto::digest::Digest;
use self::rust_crypto::sha1::Sha1;
use super::serialize::base64::{ToBase64, STANDARD};
use super::std::string::String;
pub struct RequestHeader {
pub upgrade: String,
pub connection: …Run Code Online (Sandbox Code Playgroud) 我想利用这个功能:
u8::from_str(src: &str) -> Result<u8, ParseIntError>
我似乎无法弄清楚使用它的语法.这就是我目前正在尝试的
use std::u8;
match u8::from_str("89") {
// Stuff...
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
error: unresolved name `u8::from_str`
Run Code Online (Sandbox Code Playgroud)
使用原始模块中定义的函数的正确方法是什么?
在此先感谢您的帮助!