在当前作用域中没有为std :: io :: Stdout类型找到名为flush的方法

时间:2016-11-03 02:30:14

标签: rust

我发现有关冲洗的所有文档都表明冲洗标准输出的正确方法如下:

std::io::stdout().flush().expect("some error message");

这导致

  
no method named flush found for type std::io::Stdout in the current scope

我做错了什么?

2 个答案:

答案 0 :(得分:17)

您需要导入实现flush的{​​{1}}方法的特征。

根据文件:

io::Write

因此:

Stdout

Playground example

答案 1 :(得分:7)

  

谁能告诉我我做错了什么?

是; 编译器已经

    remote:  :: Spring Boot ::        (v1.4.1.RELEASE)
remote: 
remote: 2016-11-03 08:54:00.024  INFO 93239 --- [           main] demo.Application                         : Starting Application v0.0.1-SNAPSHOT on ex-std-node853.prod.rhcloud.com with PID 93239 (/var/lib/openshift/581a74472d5271129a0000a6/app-root/runtime/repo/target/demo-0.0.1-SNAPSHOT.jar started by 581a74472d5271129a0000a6 in /var/lib/openshift/581a74472d5271129a0000a6/app-root/runtime/repo)        
remote: 2016-11-03 08:54:00.025  INFO 93239 --- [           main] demo.Application                         : The following profiles are active: openshift        
remote: 2016-11-03 08:54:00.469  INFO 93239 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@15380c2: startup date [Thu Nov 03 08:54:00 EDT 2016]; root of context hierarchy        
remote: 2016-11-03 08:54:12.437  INFO 93239 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'managementServletContext' with a different definition: replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcHypermediaManagementContextConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcHypermediaManagementContextConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration; factoryMethodName=managementServletContext; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.class]]        
remote: 2016-11-03 08:54:13.579  INFO 93239 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!        
remote: 2016-11-03 08:54:14.202  INFO 93239 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data JPA - Could not safely identify store assignment for repository candidate interface demo.repository.CustomerRepository.        
remote: 2016-11-03 08:54:15.764  INFO 93239 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!        
remote: 2016-11-03 08:54:19.720  INFO 93239 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ee91494e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)        
remote: 2016-11-03 08:54:23.293  WARN 93239 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: org/apache/catalina/SessionIdGenerator        
remote: 2016-11-03 08:54:23.337 ERROR 93239 --- [           main] o.s.boot.SpringApplication               : Application startup failed        
remote: 
remote: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is java.lang.NoClassDefFoundError: org/apache/catalina/SessionIdGenerator        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) ~[spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at demo.Application.main(Application.java:10) [classes!/:0.0.1-SNAPSHOT]        
remote:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]        
remote:     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]        
remote:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]        
remote:     at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]        
remote:     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote:     at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote:     at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote:     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote: Caused by: java.lang.NoClassDefFoundError: org/apache/catalina/SessionIdGenerator        
remote:     at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.prepareContext(TomcatEmbeddedServletContainerFactory.java:190) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:176) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.1.RELEASE.jar!/:1.4.1.RELEASE]        
remote:     ... 16 common frames omitted        
remote: Caused by: java.lang.ClassNotFoundException: org.apache.catalina.SessionIdGenerator        
remote:     at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]        
remote:     at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]        
remote:     at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:89) ~[demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote:     at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]        
remote:     ... 20 common frames omitted        
remote: 
remote: -------------------------
fn main() {
    std::io::stdout().flush().expect("some error message");
}

强调error[E0599]: no method named `flush` found for type `std::io::Stdout` in the current scope --> src/main.rs:3:23 | 3 | std::io::stdout().flush().expect("some error message"); | ^^^^^ | = help: items from traits can only be used if the trait is in scope = note: the following trait is implemented but not in scope, perhaps add a `use` for it: candidate #1: `use std::io::Write;` help行 - note

所有在一起:

use std::io::Write