我已经在模块内部实现了一个结构。我正在尝试为结构的参考切片实现io :: Read特性。
这是我的代码的简化版本。目前,新特性实施效率低下。我正在尝试不同的方法来使其正常工作。
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Question')
.addItem('Send Question', 'sendQuestion')
.addSeparator()
.addItem('Send Answer', 'sendAnswer')
.addToUi();
}
function sendQuestion() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Questions");
var range = sheet.getRange("A22:L2");
var emailvalid = range.getCell(1,7).getValue();
var question = range.getCell(1,5).getValue();
var answer = range.getCell(1,6).getValue();
var qvalid = range.getCell(1,8).getValue();
var ansvalid = range.getCell(1,10).getValue();
if(qvalid == "Nope"){
Browser.msgBox("Please, write a question !");
}
else {
return false};
if(emailvalid == "Nope"){
Browser.msgBox("Please, input a valid email address !");
}
else {
return false};
var from = range.getCell(1,1).getValue();
var recipient = range.getCell(1,2).getValue();
var emailTo = range.getCell(1,3).getValue();
var subject = "Project Management | Your received a new question" + question;
var link = "https://docs.google.com/spreadsheets/d/1QUbw0WNju55h5pk3l8QqVCYa_jSCzrIzMjf0N4v-z8c/edit?usp=sharing"
var options = {}
options.htmlBody = "Hi" + recipient +"," + "<br />"+ "<br />" + "You received a new question from " + from + "<br />" + "<br />" + "You can answer directly into the table here: "<"br />"+"<br />" + link + "<br />" + "<br />"+ "Thank you";
GmailApp.sendEmail(emailTo, subject, " ", options);
}
function emailSent(){
var ui = SpreadsheetApp.getUi();
var sent = sendQuestion("Send Email ?",ui.ButtonSet.YES_NO);
if(sent == ui.Button.YES) {
ui.alert("Your Message has been sent.");
} else {
ui.alert("Email canceled");
}
}
rust编译器一直在抱怨此错误的代码:
struct mytype {
inner: f32,
}
impl io::Read for mytype {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
buf.write_u32::<LittleEndian>(self.inner.to_bits()).unwrap();
Ok(4)
}
}
impl<'a> io::Read for &'a [mytype] {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
let mut vec8: Vec<u8> = vec![];
for t in self.iter() {
match (*t).read_u32::<LittleEndian>() {
Ok(u) => vec8.write_u32::<LittleEndian>(u).unwrap(),
Err(x) => (),
}
}
for (ind, it) in vec8.iter().enumerate() {
buf[ind] = *it;
}
Ok(vec8.len())
}
}
只需为error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> src\lib.rs:37:1
|
37 | impl<'a> io::Read for &'a [mytype] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
|
= note: the impl does not reference any types defined in this crate
= note: define and implement a trait or new type instead
实现io :: Read即可正常工作。